您的位置:首页 > Web前端 > JQuery

jQuery实现锚点scoll效果实例分析

2018-10-12 14:03 537 查看

本文实例讲述了jQuery实现锚点scoll效果的方法。分享给大家供大家参考。具体实现方法如下:

$('a[href*=#]').click(function() {
   if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
   && location.hostname == this.hostname) {
     var $target = $(this.hash);
     $target = $target.length && $target
     || $('[name=' + this.hash.slice(1) +']');
     if ($target.length) {
       var targetOffset = $target.offset().top;
       var obj = document.documentElement;
     if (jQuery.browser.safari)
           obj = document.body
    if (jQuery.browser.msie)
           obj = 'html';
      $(obj).animate({scrollTop: targetOffset}, 1000);
       return false;
     }
   }
});

希望本文所述对大家的jQuery程序设计有所帮助。

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: