【问题标题】:Smooth scrolling Bootstrap 3平滑滚动 Bootstrap 3
【发布时间】:2013-10-09 05:08:26
【问题描述】:

我在页面中尝试平滑滚动时遇到了一些问题,基本上我在页面周围有这样的锚标签:

<li><a href="#description">Module Description</a></li>
...
<section id=" description ">

我正在使用以下运行良好的 javascript,但问题是,如果我使用此脚本,bootstrap 3 的模式和其他功能会中断并且不再工作

  $('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) +']');
  if (target.length) {
    $('html,body').animate({
      scrollTop: target.offset().top
    }, 1000);
    return false;
  }
}
}); 

我想知道这个脚本有什么解决方案,或者还有其他类似的脚本用 bootstrap 3 测试过 谢谢

【问题讨论】:

    标签: javascript jquery twitter-bootstrap twitter-bootstrap-3


    【解决方案1】:

    $('a[href*=#]:not([href=#])') 将非常通用也会更改目标锚点,例如模态。尽量减少通用性:

    <ul id="insidepagenav">
    <li><a href="#description">Module Description</a></li>
    

    $('ul#insidepagenav &gt; li &gt; a[href*=#]:not([href=#])')

    【讨论】:

    • 太棒了!,非常感谢你,解决了这个问题,很乐意给你一个积极的观点,但没有足够的声誉。
    【解决方案2】:

    如果你替换

    a[href*=#]:not([href=#])
    

    与

    a[href*=#]:not([href=#]):not([href=#idname])
    

    您可以阻止平滑滚动对那个特定链接起作用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-24
      • 1970-01-01
      • 1970-01-01
      • 2013-10-20
      • 2019-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多