平滑滚动问题

时间:2013-11-18 11:45:20

标签: javascript jquery twitter-bootstrap smooth-scrolling

我正在使用以下js代码在页面上进行平滑滚动。问题是我使用以下JS后无法使用mycarousel的导航。反正有没有修复我的后续js所以它不会影响我的旋转木马导航。由于轮播导航上的#(href =“#myCarousel”),因此发生此问题。那么在这种情况下如何解决问题。

$(function() {
  $('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;
      }
    }
  });
});

我的轮播导航:

<a class="left carousel-control" href="#myCarousel" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
      <a class="right carousel-control" href="#myCarousel" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>

2 个答案:

答案 0 :(得分:0)

替换此

$('a[href*=#]:not([href=#])').click(function() {

使用:

$('a[href*=#]:not([href=#media])').click(function () { 

快乐的编码!

答案 1 :(得分:0)

这对我有用。我换了

$('a[href*=#]:not([href=#])').click(function() {

$('a[href*=#]:not([href=#carousel-example-generic])').click(function() {

其中#carousel-example-generic可以是控件指向的轮播的名称

相关问题