Profile image for mrk studios mrkstudios
jQuery animated scroll
Language
JavaScript
Tags
jquery scrolling
Favorited By
Profile image for Patrick Westerfeld Profile image for Alessandro Grassi Profile image for Gabriel Feippe Profile image for Joshua Canfield Profile image for Ben Bytes Profile image for adfasf asdfasdfadsf Profile image for Joseph Price Profile image for shai alon Profile image for Mohamed Alaa Profile image for akhil gupta Profile image for Mauro Artizzu Profile image for Tae Kim

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

Profile image for Alessandro Grassi axxe16 2011-10-20

Utile grazie!

Profile image for Landon Sanders landonsanders 2013-01-17

Awesome!