带锚点URL同一页面滚动效果的实现

得出几点结论

1,[] 在jquery选择器里

表示属性-选择
2,:not() 后置定语
3,()表示 函数参数
4,location 有好多个属性
5, animate({对象在这里}) -- 对象
------------------------------------------

jQuery(function() {
    jQuery('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
      var target = jQuery(this.hash);
      target = target.length ? target : jQuery('[name=' + this.hash.slice(1) +']');
      if (target.length) {
        jQuery('html,body').animate({
          scrollTop: target.offset().top
        }, 1000);
        return false;
      }
    }
    });
});
http://www.dreamdu.com/javascript/location.pathname/
posted @ 2015-05-04 18:18  qqisnow2021  阅读(207)  评论(0)    收藏  举报