admin管理员组文章数量:1394743
Is there a way to keep different delay time between each slide in a bxslider? Suppose I have 4 slides in the bxslider I want a delay of 1000ms between 1st and 2nd slide and 2000ms delay between third and 4th slide.
Is this possible?
Is there a way to keep different delay time between each slide in a bxslider? Suppose I have 4 slides in the bxslider I want a delay of 1000ms between 1st and 2nd slide and 2000ms delay between third and 4th slide.
Is this possible?
Share Improve this question edited Jun 8, 2013 at 12:30 Syed Hashim 1561 silver badge10 bronze badges asked Jun 8, 2013 at 12:13 ThejdeepThejdeep 2492 gold badges6 silver badges17 bronze badges3 Answers
Reset to default 5It's probably possible, but not pretty. Basically, insofar as I can tell from the documentatin for bxslider, you can't set times for specific, individual slide transition intervals. So, here's what you'd prob. need to do, in JavaScript, working with the event handlers:
Assuming the CSS selector .bxslider
gets at the HTML element housing your slider content, and the slide transition you want to make slower (2000ms) is the third to fourth slide only... and assuming you've already set up and initialized your slider, your solution could be as follows (elipses to indicate the other options that you'll set up/you've already set up, that I'm glossing over):
var slider = $('.bxslider').bxSlider({
// ...
// other params here
// ...
speed: 1000,
onSlideAfter: function (slide, oldIndex, newIndex) {
if (newIndex === 2) { // remember, it's zero based indices with bxslider...
slider.stopAuto();
setTimeout(function () {
slider.goToSlide(3);
slider.startAuto();
}, 2000);
}
}
});
Basically, we're stopping the autoplay when we hit the 3rd slide, so that we can manually control the slide "presence" duration. When the 2000 ms are up, we manually move the slider to the next frame, and restart the autoplay. If you had a larger slide show, and wanted to do this in a more organized way, it would/could look something like this:
var params = {
defaultSpeed: 1000,
speedOverrides: {
"2": 2000
// you can add other slides here,
// with the slide number used being the
// first slide of the slide transition,
// i.e., modifying the speed of 3-4, like
// above means you'd enter "2" as the
// property name, b/c again we're using
// 0-based indices.
}
};
var slider = $('.bxslider').bxSlider({
// ...
// other params here
// ...
speed: params.defaultSpeed,
onSlideAfter: function (slide, oldIndex, newIndex) {
if (params.speedOverrides[newIndex]) {
slider.stopAuto();
setTimeout(function () {
slider.goToSlide(newIndex + 1);
slider.startAuto();
}, params.speedOverrides[newIndex]);
}
}
});
I came up with a very flexible way to do this by making a small edit to the bxslider.js file. Here is the detail of my answer here: https://stackoverflow./a/17408119/700111
Use SlideBefore. The code in the answer above will stop at the last slide.
onSlideBefore: function (slide, oldIndex, newIndex) {
if (params.speedOverrides[newIndex]) {
slider.stopAuto();
setTimeout(function () {
slider.goToSlide(newIndex);
slider.startAuto();
}, params.speedOverrides[newIndex]);
}
}
本文标签: javascriptHow to apply different delays between each slide in bxsliderStack Overflow
版权声明:本文标题:javascript - How to apply different delays between each slide in bxslider - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744104395a2590999.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论