When I was developing a website. In that, I wanted to use multiple instances of flexslider on a single page. There was not the problem if ID of the container tags is different. But on my website, everything was dynamic, even how many flexslider instances were be called, that was also unknown. I had to use flexslider with thumbnails carousel also. I googled on this problem but not getting proper solution.
My problem was as follows:
HTML Structure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <div class="slider"> <div class="flexslider c_slider"> <ul class="slides"> <li> <img src="/wp-content/uploads/2012/06/2014_1.jpg" width="440" height="270" /> </li> <li> <img src="/wp-content/uploads/2012/06/2014_2.jpg" width="440" height="270" /> </li> <li> <img src="/wp-content/uploads/2012/06/2014_3.jpg" width="440" height="270" /> </li> </ul> </div> <div class="flexslider c_carousel"> <ul class="slides"> <li> <img src="/wp-content/uploads/2012/06/2014_1-140x95.jpg" width="91" height="60" /> </li> <li> <img src="/wp-content/uploads/2012/06/2014_2-140x95.jpg" width="91" height="60" /> </li> <li> <img src="/wp-content/uploads/2012/06/2014_3-140x95.jpg" width="91" height="60" /> </li> </ul> </div> </div> |
This structure renders dynamically and It can be any numbers and every thumbnail carousel should be sync with its main slider.
I was using wooTheme flexslider latest jquery plugin for getting slider. Wootheme flexslider can be implemented as follows :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | $(window).load(function() { // The slider being synced must be initialized first $('#carousel').flexslider({ animation: "slide", controlNav: false, animationLoop: false, slideshow: false, itemWidth: 210, itemMargin: 5, asNavFor: '#slider' }); $('#slider').flexslider({ animation: "slide", controlNav: false, animationLoop: false, slideshow: false, sync: "#carousel" }); }); |
Note: The slider being synced must be initialized first
It means if we want to use thumbnail carousel and sync with the main carousel then we need to initialized thumbnail carousel first and then main slider as given in above example.
Multiple instances of flex slider
There may be the different ways to implement this, but I implement multiple instances of flexslider in single page is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | jQuery(document).ready(function(){ jQuery('.c_carousel').each(function(index){ if(jQuery(".c_carousel").eq(index).length) { jQuery('.c_carousel').eq(index).flexslider({ animation: "slide", controlNav: false, directionNav:true, animationLoop: false, slideshow: true, itemWidth: 91, pausePlay: false, asNavFor: '.c_slider:eq('+index+')', itemMargin: 7, minItems: 4, maxItems: 4, move: 4 }); } if(jQuery('.c_slider').eq(index).length){ jQuery('.c_slider').eq(index).flexslider({ animation: "slide", controlNav: false , directionNav:true, animationLoop: false, slideshow: true, pausePlay: false, video: true, sync: ".c_carousel:eq("+index+")", }); } }) }); |
In above given code, I use jQuery $.each function to implement flexslider. In this loop, We are iterating ‘c_carousel’ class tags and using index, we are accessing every tag separately. Because we need to specify “asNavFor” property to associated main slider. Same as ‘asNavFor’, we need to specify ‘sync’ property to associated carousel slider.
Note: For Working these implementation, we need to set ‘animationLoop’ property as false, otherwise it won’t sync properly.
Slides in carousel should be same in numbers as associated main slider.
Great thanks..
Nice way out. Simple but effective. I did the same at an actual project thanks to you.