-2

for eg : I have a menu : Point A <a id="pointA"></a> and there is a Point B<div id="pointB"> somewhere in the body. what I wanna do is when I click on point A it should scroll to Point B but slowly.

how can I do it?

  • possible duplicate of [scrollto](http://stackoverflow.com/questions/6677035/jquery-scroll-to-element) – empiric Nov 14 '14 at 09:15

2 Answers2

1

for scrolling to your point B when point A is clicked try something like that:

$("#pointA").click(function(event) {
    event.preventDefault();
    $('html, body').animate({
        scrollTop: $("#pointB").offset().top
    }, 1500); //This value will define the speed/ duration of your animation
});
empiric
  • 7,449
  • 6
  • 35
  • 44
  • should I be loading jquery.1.11.1.js on header for this? – Pradeep Gurung Nov 14 '14 at 11:19
  • @PradeepGurung all versions of jQuery above 1.10 should work. Which one you chose depends on your other code and the browser-support. But Version 1.11 should be a good choice here – empiric Nov 14 '14 at 11:21
  • Thank you. It didn't worked but when I placed the code inside head, it worked. have you any idea about this issue?? before I wrote the script right above body end. – Pradeep Gurung Nov 14 '14 at 12:39
  • Have you tried to wrap an `$(document).ready()`-function around your code ? You should always do that – empiric Nov 14 '14 at 12:52
  • yes I did `` – Pradeep Gurung Nov 15 '14 at 03:15
0
You can write below code for scroll to div pointB 

<script>
$(function(){
$("#pointA").bind("click",function(event) {
    $('body').animate({
        scrollTop: $("#pointB").offset().top},
    1000); 
});});
</script>