- jQuery animated scroll
- Language
- JavaScript
- Tags
- jquery scrolling
- Favorited By
jQuery animated scroll
1 // ANIMATED SCROLL
2
3 $(".scroll").click(function(event)
4 {
5 //prevent the default action for the click event
6 event.preventDefault();
7
8 //get the full url - like mysitecom/index.htm#home
9 var full_url = this.href;
10
11 //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
12 var parts = full_url.split("#");
13 var trgt = parts[1];
14
15 //get the top offset of the target anchor
16 var target_offset = $("#"+trgt).offset();
17 var target_top = target_offset.top;
18
19 //goto that anchor by setting the body scroll top to anchor top
20 $('html, body').animate({scrollTop:target_top}, 500);
21 });
Comments
-
axxe16 2011-10-20
Utile grazie!
-
landonsanders 2013-01-17
Awesome!
Sign in to leave a comment.

