猿问

关于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) +']') 这个是应该怎么理解的?

Cats萌萌
浏览 624回答 1
1回答

犯罪嫌疑人X

找锚点指向的元素 比如锚点是&nbsp;锚点的对象可能是<div id="top"></div>或者<div name="top"></div>
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答