关于jq的插件研究

$('a[href*="#"]:not([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) +']');
      console.log( $('[name=' + this.hash.slice(1) +']'));
      if (target.length) {
        $('html, body').animate({
          scrollTop: target.offset().top
        }, 1000);
        return false;
      }
    }
  });

这是个锚点滚动插件,看了下有一点不是很明白,$('[name=' + this.hash.slice(1) +']') 这个是应该怎么理解的?

阅读 2.5k
1 个回答

找锚点指向的元素 比如锚点是
锚点的对象可能是<div id="top"></div>或者<div name="top"></div>

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题