Syncing two flexslider together on touch swipe
Posted By : Deepak Rawat | 30-Sep-2014
Woothemes introduces an awesome jquery slider which is fully responsive and easy to use which is known as flexslider.
There is an option in this plugin for syncing two flexslider with each other which is good but its not working very well for touch devices. On touch devices when we swipe one slider then other slider didn't move with it, so I tweak its library and added some line of code in it to work it for touch swipe. Now when you swipe the first slider the second slider will also moves with it.
Now for syncing you have to first initialise both the sliders like this :
$(window).load(function() {
$('#carousel').flexslider({
animation: "slide",
controlNav: false,
animationLoop: false,
slideshow: false
});
$('#slider').flexslider({
animation: "slide",
controlNav: false,
animationLoop: false,
slideshow: false,
sync: "#carousel"
});
});
Then go to the flexslider library and copy-paste this code in onTouchMove() function
if (slider.syncExists) {
var $obj = $(slider.vars.sync).data("flexslider");
$obj.setProps(offset + dx, "setTouch");
}
and this code in onTouchEnd() function
if (slider.syncExists) {
var $obj = $(slider.vars.sync).data("flexslider");
$obj.flexAnimate(slider.currentSlide, slider.vars.pauseOnAction, true);
}
When all setup is done you are good to go.
If any issue occurs feel free to ask.
NOTE : Always initialise the slider to be synced first. And the width of both the slider should be same.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Deepak Rawat
Deepak is a Web and Mobile application Sr. Lead Frontend developer and good working experience with JQuery , AngularJS , Javascript and PhoneGap. His hobbies are listening to music and photography.