javascript bxSlider 不自动工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16896193/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
bxSlider not working automatically
提问by user961627
I want the bxSlider to automatically start the slideshow without the user clicking on it. This is my code (which isn't working):
我希望 bxSlider 无需用户单击即可自动启动幻灯片。这是我的代码(不起作用):
slider = $('.slider1').bxSlider({
slideWidth: 1012,
slideHeight:200,
minSlides: 1,
slideMargin: 0,
controls: false,
auto: true,
autoStart: true
});
slider.startAuto();
What's wrong with this? What happens is that images do load, but it never autoscrolls, the user always have to choose one of the pager dots to manually scroll through. What's wrong with my code?
这有什么问题?发生的情况是图像确实加载了,但它从不自动滚动,用户总是必须选择一个寻呼机点来手动滚动。我的代码有什么问题?
回答by Raa
You should use
你应该使用
$(document).ready(function(e) { });
or
或者
$(window).ready(function(e) { });
in between the code.
在代码之间。
so the correct one should be,
所以正确的应该是
$(document).ready(function(e) {
$('.slider1').bxSlider({
slideWidth: 1012,
slideHeight:200,
minSlides: 1,
slideMargin: 0,
controls: false,
auto: true,
});
});
hope this will help you...!
希望能帮到你...!
回答by ImranNaqvi
This was all , what was missing and i got it from bxslider official
page
这就是全部,缺少什么,我从bxslider official
页面上找到了
$(document).ready(function(){
$('.bxslider').bxSlider({
mode: 'fade',
auto: true,
autoControls: true,
pause: 2000
});
});
回答by KlaasvnA
This Code worked for me!
此代码对我有用!
var slider = $('#slider').bxSlider();
$('.bx-next, .bx-prev, .bx-pager a').click(function(){
// time to wait (in ms)
var wait = 1000;
setTimeout(function(){
slider.startAuto();
}, wait);
});
You can set wait on 0 if you don't want a delay. And because I used: pagerCustom: '#pager', I changed '.bx-pager' a into '#pager a'.
如果您不想延迟,可以将等待设置为 0。因为我使用了:pagerCustom: '#pager',所以我将 '.bx-pager' a 更改为 '#pager a'。
回答by Raj Kumar
Okay! I got the same problem! And none of the solution worked above. But I found what was wrong!
好的!我遇到了同样的问题!并且没有一个解决方案在上面起作用。但是我发现哪里不对了!
1 - First Check and make sure you have auto:true
in jQuery script like below:
1 - 首先检查并确保您auto:true
在 jQuery 脚本中有如下内容:
$('.bxslider').bxSlider({
auto: true,
pause: 3000,
pager: true
});
2 - The main jQuery file that you are using, kindly update that jQuery file, you might be using old jQuery file! (#2 was the issue in case of mine)
2 - 您正在使用的主要 jQuery 文件,请更新该 jQuery 文件,您可能正在使用旧的 jQuery 文件!(#2 是我的问题)
Thanks!
谢谢!
回答by FarmerGedden
Try setting autoControls: true
(from http://bxslider.com/examples/auto-show-start-stop-controls)
尝试设置autoControls: true
(来自http://bxslider.com/examples/auto-show-start-stop-controls)
回答by Erkan KAVAS
I suggest the following remedy. onSlideAfter
is executed after each slide transition. Then this code will cause slider.startAuto()
to be executed each time this happens, starting auto show.
我建议采取以下补救措施。onSlideAfter
在每次幻灯片转换后执行。然后slider.startAuto()
每次发生这种情况时都会执行此代码,启动自动显示。
var slider = $(".sliderBx ul").bxSlider({
auto: true,
pager: true,
controls: true,
onSlideAfter: function () {
slider.startAuto();
}
});