scroll.js 632 B

1234567891011121314151617181920
  1. $(document).ready(function(){
  2. $(".scroll").click(function(event){
  3. //prevent the default action for the click event
  4. event.preventDefault();
  5. //get the full url - like mysitecom/index.htm#home
  6. var full_url = this.href;
  7. //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
  8. var parts = full_url.split("#");
  9. var trgt = parts[1];
  10. //get the top offset of the target anchor
  11. var target_offset = $("#"+trgt).offset();
  12. var target_top = target_offset.top;
  13. //goto that anchor by setting the body scroll top to anchor top
  14. $('html, body').animate({scrollTop:target_top}, 500);
  15. });
  16. });