如何检查是否在 bxslider 中启用了自动播放
How to check if auto-play is enabled in bxslider
单击按钮 (#my-button) 后,我想检查是否为滑块启用了自动播放功能。我在下面尝试过,但它返回了未定义的对象
var slider = $('.bxslider').bxSlider({
auto: true,
autoControls: true
});
$('#my-button').click(function(){
console.log(slider.auto);
});
除了确定是否启用自动的明显方法(即查看滑块是否自行移动)之外,我们还可以看到哪个自动控制按钮,.bx-start
and/or .bx-stop
有 class .active
.
片段
var slider = $('.bx').bxSlider({
auto: true,
autoControls: true
});
$('.status').click(function() {
if ($('.bx-stop').hasClass('active')) {
console.log('Auto is inactive');
$('.display').val('Inactive');
} else {
console.log('Auto is active');
$('.display').val('Active');
}
});
img {
display: block;
margin: 0 auto;
}
button {
font: inherit;
}
<link href='https://cdn.jsdelivr.net/bxslider/4.2.5/jquery.bxslider.css' rel='stylesheet'>
<ul class='bx'>
<li class='slide'><img src='http://placehold.it/250x150/000/fff?text=1'></li>
<li class='slide'><img src='http://placehold.it/250x150/00f/eee?text=2'></li>
<li class='slide'><img src='http://placehold.it/250x150/0e0/111?text=3'></li>
<li class='slide'><img src='http://placehold.it/250x150/f00/fff?text=4'></li>
<li class='slide'><img src='http://placehold.it/250x150/fc0/000?text=5'></li>
<li class='slide'><img src='http://placehold.it/250x150/fff/000?text=6'></li>
</ul>
<button class='status'>Status</button>
<output class='display'></output>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src='https://cdn.jsdelivr.net/bxslider/4.2.5/jquery.bxslider.min.js'></script>
单击按钮 (#my-button) 后,我想检查是否为滑块启用了自动播放功能。我在下面尝试过,但它返回了未定义的对象
var slider = $('.bxslider').bxSlider({
auto: true,
autoControls: true
});
$('#my-button').click(function(){
console.log(slider.auto);
});
除了确定是否启用自动的明显方法(即查看滑块是否自行移动)之外,我们还可以看到哪个自动控制按钮,.bx-start
and/or .bx-stop
有 class .active
.
片段
var slider = $('.bx').bxSlider({
auto: true,
autoControls: true
});
$('.status').click(function() {
if ($('.bx-stop').hasClass('active')) {
console.log('Auto is inactive');
$('.display').val('Inactive');
} else {
console.log('Auto is active');
$('.display').val('Active');
}
});
img {
display: block;
margin: 0 auto;
}
button {
font: inherit;
}
<link href='https://cdn.jsdelivr.net/bxslider/4.2.5/jquery.bxslider.css' rel='stylesheet'>
<ul class='bx'>
<li class='slide'><img src='http://placehold.it/250x150/000/fff?text=1'></li>
<li class='slide'><img src='http://placehold.it/250x150/00f/eee?text=2'></li>
<li class='slide'><img src='http://placehold.it/250x150/0e0/111?text=3'></li>
<li class='slide'><img src='http://placehold.it/250x150/f00/fff?text=4'></li>
<li class='slide'><img src='http://placehold.it/250x150/fc0/000?text=5'></li>
<li class='slide'><img src='http://placehold.it/250x150/fff/000?text=6'></li>
</ul>
<button class='status'>Status</button>
<output class='display'></output>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src='https://cdn.jsdelivr.net/bxslider/4.2.5/jquery.bxslider.min.js'></script>