如何将Twitter Bootstrap轮播循环函数可以更改为将项从右到左循环而不是从左到右,因此在希伯来语/阿拉伯语网站?Twitter Bootstrap循环轮播项目从右到左(RTL)反转
回答
只需重写周期函数调用类似功能的上一页代替下一个:
$(document).ready(function() {
$('.carousel').each(function(){
$(this).carousel();
var carousel = $(this).data('bs.carousel'); // or .data('carousel') in bootstrap 2
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 (it'll work only for the first slide)
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;
};
carousel.cycle();
});
});
使用
var carousel = $(this).data('bs.carousel');
代替
var carousel = $(this).data('carousel');
在引导3
解释原因如何? – Lankymart
这是对我的答案的改进吗?你应该把它写成对我的答案的评论,而不是一个不同的答案。 –
我做不同的事情,懒得坚持自己的解决方案(太冗长对我来说):
我的设置:ASP.NET MVC,文化设置:希伯来语。 我的轮播实例位于名为“divTopNewsSlider”的div下。 “.slideshow-prev”和“.slideshow-next”是我的prev和next图标的选择器。
解决步骤:
确定用户的文化(我开发一个内容管理系统,所以我需要从服务器获取的区域性设置)。
用它来确定旋转木马元素的浮动方向。
分别将轮播滑块的下一个和上一个功能更改为反向。
在剃刀:
@functions {
Boolean IsRTL()
{
return this.CultureDictionary.Language.CultureAlias.ToLower().IndexOf("he-il") > -1;
}
}
在JavaScript:
<script type="text/javascript">
var isRTL = "@IsRTL()".toLowerCase() === 'true';
$(".slideshow .pager li").css("float", isRTL ? "right" : "left");
$(document).ready(function() {
if (isRTL) {
$(".slideshow-prev").click(function() {
$("#divTopNewsSlider").carousel('next');
event.stopPropagation();
});
$(".slideshow-next").click(function() {
$("#divTopNewsSlider").carousel('prev');
event.stopPropagation();
});
}
});
</script>
如何扭转通过CSS
的引导旋转木马我有只CSS的解决方案。没有新的脚本。不改变HTML。
- 使图像变得宽广和响应。
- 更改指标的顺序。将它们返回到幻灯片的中心。
- 更改转换方向。
请检查结果:
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
/* 1 */
#myCarousel img {
height: auto;
max-width: 100%;
width: 100%;
}
/* 2 */
.carousel-indicators {
width: auto;
margin-left: 0;
transform: translateX(-50%);
}
.carousel-indicators li {
float: right;
margin: 1px 4px;
}
.carousel-indicators .active {
margin: 0 3px;
}
/* 3 */
@media all and (transform-3d), (-webkit-transform-3d) {
.carousel-inner > .item.next,
.carousel-inner > .item.active.right {
left: 0;
-webkit-transform: translate3d(-100%, 0, 0);
transform: translate3d(-100%, 0, 0);
}
.carousel-inner > .item.prev,
.carousel-inner > .item.active.left {
left: 0;
-webkit-transform: translate3d(100%, 0, 0);
transform: translate3d(100%, 0, 0);
}
}
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="//placehold.it/900x300/c69/f9c/?text=1" alt="First slide">
</div>
<div class="item">
<img src="//placehold.it/900x300/9c6/cf9/?text=2" alt="Second slide">
</div>
<div class="item">
<img src="//placehold.it/900x300/69c/9cf/?text=3" alt="Third slide">
</div>
</div>
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span><span class="sr-only">Previous</span></a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span><span class="sr-only">Next</span></a>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
对于RTL语言,如波斯语,阿拉伯语和希伯来语
在bootstrap.js文件,找到&改变这一行:
var delta = direction == 'prev' ? -1 : 1
到:
var delta = direction == 'prev' ? 1 : -1
也
Carousel.prototype.next = function() {
if (this.sliding) return
return this.slide('next')
}
Carousel.prototype.prev = function() {
if (this.sliding) return
return this.slide('prev')
}
到:
Carousel.prototype.next = function() {
if (this.sliding) return
return this.slide('prev')
}
Carousel.prototype.prev = function() {
if (this.sliding) return
return this.slide('next')
}
- 1. 从右到左(RTL)瓷砖
- 2. Twitter Bootstrap右拉和左拉用于RTL语言
- 3. SASS项目中的从右到左(RTL)支持
- 4. Twitter Bootstrap 2.3.2轮播:上次滑动后的无限循环
- 5. Twitter bootstrap topbar rtl
- 6. 循环显示图像从db到bootstrap轮播
- 7. 引导RTL(从右到左)输入组
- 8. Bootstrap 3 Collapse(从左到右)
- 9. Bootstrap 3 Collapse(从右到左)
- 10. Android从右到左NavigationDrawer菜单项不是RTL
- 11. Twitter Bootstrap旋转木马 - 不要循环
- 12. 如何使用twitter-bootstrap跨越从右到左?
- 13. Twitter bootstrap - IE中的左右边距
- 14. 从左到右移动UITableView项目
- 15. Twitter Bootstrap轮播响应不正常
- 16. Twitter Bootstrap rtl评级星级
- 17. 从右向左设置qTip2方向(RTL)
- 18. CSS转换是从左到右,而不是从右到左
- 19. 如何翻转两个LinearLayout从右到左和从左到右
- 20. Twitter Bootstrap&Spree项目?
- 21. Bootstrap推送菜单从右到左
- 22. 左右TableLayout项目
- 23. 如何获得循环轮播中jcarousel项目的索引号
- 24. css轮廓左右
- 25. cssJanus停止反转到rtl
- 26. npm bootstrap-rtl for angular-2 cli项目
- 27. PictureBox反复从左到右移动
- 28. 从右到左语言支架反
- 29. TextBox输入从右到左,但dir =“rtl”不完整
- 30. ITextPdf:从右到左(RTL)打印阿拉伯文字符串
对我来说是行不通的,因为不同的引导版本的可能。我使用var carousel = $(this).data('bs.carousel'); – tovmeod
现在如何反转指标? – tovmeod
它为我工作,但间隔停止响应我发送的财产,例如'$('#carousel')。carousel({interval:500});' –