美文网首页
原生js锚点滑动

原生js锚点滑动

作者: krystal_H | 来源:发表于2019-09-30 17:30 被阅读0次
// 锚点滑动
Menu.goSlide = function () {
  document.querySelectorAll('.link_a').forEach(function (el) {
    el.addEventListener('click', function () {
     var target = document.querySelector('div[data-tab=' + this.getAttribute('data-tab') + ']')
      target.scrollIntoView({ behavior: "smooth", block: "start", inline: "nearest" })
    })
  })
}

结构


image.png
image.png

相关文章

网友评论

      本文标题:原生js锚点滑动

      本文链接:https://www.haomeiwen.com/subject/bskhpctx.html