2016-02-16 62 views
1

我使用下面的js代碼改變引導傳送帶在阿拉伯語「升」的方向。我需要將輪播方向更改爲'ltr',但以下js代碼無法正常工作。如何改變引導轉盤方向

是否有任何人誰將會調試此問題。

JQuery的

var theLanguage = $('html').attr('lang'); 
if(theLanguage == 'en') { 

    $('.carousel').carousel({ 
     direction:'left', 
    }); 
} 

else{ 

    $('.carousel').carousel({ 
     direction:'right', 
    }) 
} 
+0

有沒有人誰擁有的技能來改變引導旋轉木馬在阿拉伯語「升」和英語 –

+0

希望這將幫助, [Twitter的引導旋轉木馬週期項目從右至左「RTL」的方向(RTL )逆轉(http://stackoverflow.com/questions/16877562/twitter-bootstrap-carousel-cycle-items-right-to-left-rtl-reversed) –

+0

爲瀏覽器語言檢測:[鏈接](HTTP:// stackoverflow.com/a/18317523/5393271) – sTx

回答

1

通過重寫循環功能你可以把它稱之爲分組,而不是下一個在每個週期。

Take a look at my working example here

$(document).ready(function() { 
    $('.carousel').each(function(){ 

     // find carousel 
     $(this).carousel(); 

     var carousel = $(this).data('bs.carousel'); 

     // pause the cycle 
     carousel.pause(); 

     // At first, reverse the order of the items in the carousel because we're moving backwards 
     $(this).find('> .carousel-inner > .item:not(:first-child)').each(function() { 
      $(this).prependTo(this.parentNode); 
     }); 

     // Override the bootstrap carousel prototype function, adding a different one won't work 
     carousel.cycle = function (e) { 
      if (!e) this.paused = false 
      if (this.interval) clearInterval(this.interval); 
      this.options.interval 
      && !this.paused 
      && (this.interval = setInterval($.proxy(this.prev, this), this.options.interval)) 
      return this; 
     }; 

     // begin the cycle again 
     carousel.cycle(); 
    }); 
}); 
+0

我很想推薦輪播的擴展,而不是僅僅覆蓋其循環方法。你可以只創建一個'ReversibleCarousel'例如,並且提供做同樣的事情爲你做重寫一個額外的方法,但保留正常'cycle'方法到位,方便以後調用。 – Jeremy