admin管理员组文章数量:1335357
I have three different slider with different number of slide visible on each. How do I keep all three different swiper slider in sync? I do know for two slider we can do something like this:
sliderOne.controller.control = sliderTwo;
sliderTwo.controller.control = sliderOne;
I want when someone change sliderOne to change sliderTwo and sliderThree also and vice-versa. When I do something like this:
sliderOne.controller.control = sliderTwo;
sliderTwo.controller.control = sliderOne;
sliderThree.controller.control = sliderOne;
sliderThree is able to change/control sliderOne but sliderOne is only controlling sliderTwo not both sliderTwo and sliderThree.
Can anyone suggest me how to change sliderTwo and sliderThree both through sliderOne? Think like sliderOne is thumbnails for both sliderTwo and sliderThree.
I have three different slider with different number of slide visible on each. How do I keep all three different swiper slider in sync? I do know for two slider we can do something like this:
sliderOne.controller.control = sliderTwo;
sliderTwo.controller.control = sliderOne;
I want when someone change sliderOne to change sliderTwo and sliderThree also and vice-versa. When I do something like this:
sliderOne.controller.control = sliderTwo;
sliderTwo.controller.control = sliderOne;
sliderThree.controller.control = sliderOne;
sliderThree is able to change/control sliderOne but sliderOne is only controlling sliderTwo not both sliderTwo and sliderThree.
Can anyone suggest me how to change sliderTwo and sliderThree both through sliderOne? Think like sliderOne is thumbnails for both sliderTwo and sliderThree.
Share Improve this question asked Mar 29, 2019 at 12:53 Abhishek RajAbhishek Raj 1071 gold badge3 silver badges10 bronze badges 1- What you're looking for is Observer pattern :) – Zyigh Commented Mar 29, 2019 at 12:59
2 Answers
Reset to default 4You can pass array to controller.control
So final code will be
sliderOne.controller.control = [sliderTwo, sliderThree];
Link to the docs: Docs
You can redeclare the setTranslate
& setTransition
if sizes are the same:
function bindSwipers(...swiperList) {
for (const swiper of swiperList) {
swiper.setTranslate = function(translate, byController, doNotPropagate){
if (doNotPropagate) {
Swiper.prototype.setTranslate.apply(this, arguments);
} else {
for (const swiper of swiperList) {
swiper.setTranslate(translate, byController, true);
}
}
};
swiper.setTransition = function(duration, byController, doNotPropagate){
if (doNotPropagate) {
Swiper.prototype.setTransition.apply(this, arguments);
} else {
for (const swiper of swiperList) {
swiper.setTransition(duration, byController, true);
}
}
};
}
}
bindSwipers(sliderOne, sliderTwo, sliderThree);
or slideTo
:
function bindSwipers(...swiperList) {
for (const swiper of swiperList) {
swiper.slideTo = function(index, speed, runCallbacks, doNotPropagate){
if (doNotPropagate) {
Swiper.prototype.slideTo.apply(this, arguments);
} else {
for (const swiper of swiperList) {
swiper.slideTo(index, speed, runCallbacks, true);
}
}
};
}
}
bindSwipers(sliderOne, sliderTwo, sliderThree);
本文标签: javascriptHow to sync three swiper sliderStack Overflow
版权声明:本文标题:javascript - How to sync three swiper slider? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742354821a2459197.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论