引导程序转盘隐藏第一个和最后一个控件
bootstrap carousel hide controls on first and last
如果转盘在第一个项目上,我如何隐藏左侧控件,如果转盘在最后一个项目上我如何隐藏右侧控件。
我下面的代码成功地隐藏了控件,但在页面加载时,就好像旋转木马的第一个项目位于中间,用户可以通过左侧或右侧控件进行所有操作。
http://bootply.com/99354
感谢
引导链接
$('#myCarousel').on('slid', '', checkitem); // on caroussel move
$('#myCarousel').on('slid.bs.carousel', '', checkitem); // on carousel move
$(document).ready(function(){ // on document ready
checkitem();
});
function checkitem() // check function
{
var $this = $('#myCarousel');
if($('.carousel-inner .item:first').hasClass('active')) {
$this.children('.left.carousel-control').hide();
$this.children('.right.carousel-control').show();
} else if($('.carousel-inner .item:last').hasClass('active')) {
$this.children('.left.carousel-control').show();
$this.children('.right.carousel-control').hide();
} else {
$this.children('.carousel-control').show();
}
}
下面的代码是TheLittlePig针对Bootstrap 3的代码的更新版本,它既适用于同一页面上的多个转盘,也适用于指示器操作。解释的代码在这里
checkitem = function() {
var $this;
$this = $("#slideshow");
if ($("#slideshow .carousel-inner .item:first").hasClass("active")) {
$this.children(".left").hide();
$this.children(".right").show();
} else if ($("#slideshow .carousel-inner .item:last").hasClass("active")) {
$this.children(".right").hide();
$this.children(".left").show();
} else {
$this.children(".carousel-control").show();
}
};
checkitem();
$("#slideshow").on("slid.bs.carousel", "", checkitem);
Augmenting@TheLittlePig,如果您使用Bootstrap 3,它需要略有不同,因为要将回调附加到的事件不同:slid.bs.carousel
。此外,如果一个页面上有多个转盘,则需要将转盘的唯一css id传递到事件处理程序中。这是我在Rails网站上使用的一个修改版本:
<script>
//<![CDATA]
id = '#carousel-<%=id%>';
$(id).on('slid.bs.carousel', { id: id }, bs_carousel_slid);
$(document).ready(function(){ $(id).trigger('slid.bs.carousel'); });
//]]>
</script>
对每个转盘重复此操作。<%=id%>
是一个ruby表达式,它被给定转盘的唯一id所取代。根据你选择的语言,根据你的需要调整一下。
不同之处在于,转盘的id作为事件数据传递到事件处理程序函数中,以便事件处理程序可以在正确的转盘上操作。我还更改了ready
事件,使其触发slid.bs.carousel
事件(而不是直接调用函数),从而将正确的事件数据传递给每个转盘的事件处理程序。
事件处理程序是一个名为bs_carousel_slid
的函数,我在其他地方定义了它(Rails上的函数-它在app/assets/javascripts
中的一个文件中)。功能如下所示:
function bs_carousel_slid(event)
{
var id = event.data.id;
var $this = $(id);
if($(id + ' .carousel-inner .item:first').hasClass('active')) {
$this.children('.left.carousel-control').hide();
} else if($(id + ' .carousel-inner .item:last').hasClass('active')) {
$this.children('.right.carousel-control').hide();
} else {
$this.children('.carousel-control').show();
}
}
如果您正在使用BOOTSTRAP 3:
事件是"滑动.bs.carousel"而不是"滑动"
$('.carousel').carousel({
interval: false,
})
$(document).ready(function () { // on document ready
checkitem();
});
$('#myCarousel').on('slid.bs.carousel', checkitem);
function checkitem() // check function
{
var $this = $('#myCarousel');
if ($('.carousel-inner .item:first').hasClass('active')) {
$this.children('.left.carousel-control').hide();
} else if ($('.carousel-inner .item:last').hasClass('active')) {
$this.children('.right.carousel-control').hide();
} else {
$this.children('.carousel-control').show();
}
}
- 后焦点更改为IE 11中的地址栏,而不是转移到表单中的下一个控件
- 用键盘分页jQuery下一个和上一个控件.触发器('点击')不'不起作用
- 引导程序转盘隐藏第一个和最后一个控件
- 如何从另一个控件调用 onclick 事件
- 通过锚标记将另一个控件的客户端 ID 发送到 JavaScript
- 使用 jQuery $.ajax 调用另一个控件的操作
- 非常简单的幻灯片放映,带有上一个和下一个控件
- 自定义指令如何知道它是否已单击另一个控件
- Javascript在onclick上验证两个控件,但如果只有一个控件验证,则不保留值
- jQuery的函数不依赖于另一个控件的值
- 引导程序3:第一个和最后一个项目的徒步旅行转盘控件不起作用
- 以角度js将值从一个控件传递到另一个控件
- 在切换到asp.net中的另一个控件之前,请验证选项卡中的控件
- 如何向幻灯片添加下一个和上一个控件
- 自定义控件——如何在另一个控件中封装聚合
- 如何在jQuery Mobile中正确地将单选框分组到一个控件
- onclickjavascript将值发送到另一个控件
- 焦点在另一个控件上,但按enter键会按默认按钮
- 在asp.net中输入Key作为Tab并将焦点移动到下一个控件
- 在aspx页面中加载一个又一个控件