10

I have a link which changes its vertical position on scrolling. I want to go to a certain postion (smoothly) on my page when I click this link, which is located exactly 1080px from the top of the page.

I can't get it work, hope someone can help me out.

The link:

<img src="img/clickme.png" style="cursor: pointer;" class="scroll"/>

The script:

<script type="text/javascript">
$(document).ready(function() {
$(".scroll").click(function(event){     
$('html, body').animate({scrollTo({ top: '+1080px',}, 800);
});
});
</script>
user1715848
  • 113
  • 1
  • 1
  • 4

1 Answers1

22

Try this instead. Your syntax was off a little:

$(document).ready(function() {
    $(".scroll").click(function(event){
        $('html, body').animate({scrollTop: '+=1080px'}, 800);
    });
});

Demo: http://jsfiddle.net/m4Aaz/2/

Blender
  • 289,723
  • 53
  • 439
  • 496
  • How can i stop this scrolling?? i cannot stop this scrolling by " $('html, body').stop()" . ?? could you please suggest a way?? Thank you – Eann Nov 11 '14 at 09:19