簡體   English   中英

當左右滑動控制時,Twitter Bootstrap Carousel繼續向上移動

[英]Twitter Bootstrap Carousel keeps moving up when sliding control left or right

我的bootstrap 3.3輪播(直接從getbootstrap.com獲取的代碼)每次我向左或向右導航/滑動控件時都會一直向上移動到瀏覽器頂部。

因此,如果輪播位於頁面中間,並且您開始手動滑動,則會將整個頁面向上移動,直到輪播到達瀏覽器頂部。

示例: http//crevisio.com/branding/pLXAsNJdn

我怎么能糾正這個?

這是導致Web向上滾動的代碼:

$('a[href*=#]').each(function() {
var thisPath = filterPath(this.pathname) || locationPath;
if (  locationPath == thisPath
&& (location.hostname == this.hostname || !this.hostname)
&& this.hash.replace(/#/,'') ) {
  var $target = $(this.hash), target = this.hash;
  if (target) {
    var targetOffset = $target.offset().top;
    $(this).click(function(event) {
      event.preventDefault();
      $(scrollElem).animate({scrollTop: targetOffset}, 800, function() { // <== DISABLE THIS AND THE NEXT 2 LINES
        location.hash = target;
      });
    });
  }
}

});

問題是 - 為什么將click事件綁定到包含# ?的href屬性的每個A元素?

href="#carousel-branding-project"木馬的HTML定義中的href="#carousel-branding-project"會導致您的頁面鏈接到id="carousel-branding-project" ,這是您的輪播的父div。

如果您需要將其作為錨點,請嘗試將鏈接更改為href="javascript:void(0)"

  <a class="left carousel-control" href="javascript:void(0)"role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
  </a>
  <a class="right carousel-control" href="javascript:void(0)" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right"></span>
  </a>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM