Tag Archives: top

Scroll to given element on the page.


 

Some examples about how to scroll to a given page element.

All this code must be wrapped into <script type="text/javascript>custom code stays here</script> tags.

 

Scroll to the element on page load:

 

$(window).load(function() {

$('html, body').animate({ scrollTop: $("<selector>").offset().top},2000);

});

 

Scroll to the element on page ready:

 


$(document).ready(function() {

$('html, body').animate({ scrollTop: $("<selector>").offset().top},2000);

});

 

Scroll to the element on click:

 


$("<selector>").click(function{

$('html, body').animate({ scrollTop: $("<selector>").offset().top},2000);

});

 

2000 - Time in milliseconds (1000 ms = 1 s) that the animation needs to complete. Reduce the amount for quicker and increase for slower motion.

 

More info about the <selector> and how to use it here: JQuery selectors - how to select items on page properly

 

Print  posted by atanas   Jquery/Ajax tags:  javascript • scroll • top   permalink
5 1


[home] 


CATEGORIES



TAGS


RECENT ENTRIES