jQuery FlexSlider and carousel thumbnail navigation
-
13-12-2019 - |
Question
I am using jQUery FlexSlider the following is my code
<link rel="stylesheet" type="text/css" href="css/gallery/shCore.css" />
<link rel="stylesheet" type="text/css" href="css/gallery/shThemeDefault.css" />
<link rel="stylesheet" type="text/css" href="css/gallery/flexslider.css" />
<script type="text/javascript" src="js/gallery/modernizr.js"></script>
<script type="text/javascript" src="js/gallery/jquery.flexslider.js" ></script>
<script type="text/javascript" src="js/gallery/shCore.js"></script>
<script type="text/javascript" src="js/gallery/shBrushXml.js"></script>
<script type="text/javascript" src="js/gallery/shBrushJScript.js"></script>
<script type="text/javascript" src="js/gallery/jquery.easing.js"></script>
<script type="text/javascript" src="js/gallery/jquery.mousewheel.js"></script>
And the following isin body
<body>
<div id="slider" class="flexslider">
<ul class="slides">
<li >
<img src="images/gallery/1.jpg" alt="image01" data-description="Fiesta Gallery" height="299px" width="450px" />
</li>
<li >
<img src="images/gallery/2.jpg" alt="image01" data-description="Fiesta Gallery" height="299px" width="450px"/>
</li>
<li >
<img src="images/gallery/3.jpg" alt="image01" data-description="Fiesta Gallery" height="299px" width="450px" />
</li>
<li >
<img src="images/gallery/4.jpg" alt="image01" data-description="Fiesta Gallery" height="299px" width="450px" />
</li>
<li >
<img src="images/gallery/5.jpg" alt="image01" data-description="Fiesta Gallery" height="299px" width="450px" />
</li>
<li >
<img src="images/gallery/6.jpg" alt="image93" data-description="Fiesta Gallery" height="299px" width="450px" />
</li>
<li >
<img src="images/gallery/7.jpg" alt="image97" data-description="Fiesta Gallery" height="299px" width="450px" />
</li>
<li >
<img src="images/gallery/8.jpg" alt="image108" data-description="Fiesta Gallery" height="299px" width="450px" />
</li>
</ul>
</div>
<div id="carousel" class="flexslider" style="margin-top:-50px;">
<ul class="slides">
<li >
<img src="images/gallery/thumbs/1.jpg" height="100px" />
</li>
<li >
<img src="images/gallery/thumbs/2.jpg" height="100px" />
</li>
<li >
<img src="images/gallery/thumbs/3.jpg" height="100px" />
</li>
<li >
<img src="images/gallery/thumbs/4.jpg" height="100px" />
</li>
<li >
<img src="images/gallery/thumbs/5.jpg" height="100px" />
</li>
<li >
<img src="images/gallery/thumbs/6.jpg" height="100px" />
</li>
<li >
<img src="images/gallery/thumbs/7.jpg" height="100px" />
</li>
<li >
<img src="images/gallery/thumbs/8.jpg" height="100px" />
</li>
</ul>
</div>
</body>
And the following is configuration in the head section
$(function(){
SyntaxHighlighter.all();
});
$(window).load(function() {
// The slider being synced must be initialized first
$('#carousel').flexslider({
animation: "slide",
controlNav: false,
animationLoop: true,
directionNav: false,
slideshow: false,
slideshowSpeed: 7500,
animationSpeed: 400,
itemWidth: 150,
itemMargin: 5,
startAt: 0,
move : 3,
asNavFor: '#slider'
});
$('#slider').flexslider({
animation: "slide",
controlNav: false,
animationLoop: true,
slideshowSpeed: 7500,
animationSpeed: 400,
pauseOnAction: false,
slideshow: true,
startAt: 0,
sync: "#carousel",
start: function(slider) {
$('#carousel .slides li img').click(function(event){
event.preventDefault();
//slider.flexAnimate(slider.getTarget("next"));
var count = slider.currentSlide + 1;
slider.flexAnimate(count);
});
}
});
});
From above code, I can do auto slide, Left/Right buttons navigation and in some thumnails click it works.
But if i click on two thumbnails behind from current thumbnail, it stop the auto sliding.
How can i fix this? Any help will apprecite.
Thanks in adavnce!!
Solution
I replace with the following code: it works
start: function(slider) {
$('#carousel .slides li img').click(function(event){
$('#slider').flexslider("play");
});
}
I can figure out from the reference: https://github.com/woothemes/FlexSlider/
OTHER TIPS
Here is the HTML structure
<div class="g-s-wrapper">
<div class="flexslider">
<ul class="slides">
<li data-thumb="assets/img/gallery-photo/1.jpg">
<img src="assets/img/gallery-photo/1.jpg" alt="">
</li>
<li data-thumb="assets/img/gallery-photo/2.jpg">
<img src="assets/img/gallery-photo/2.jpg" alt="">
</li>
</ul> <!-- .slides -->
</div> <!-- .flexslider -->
</div> <!-- .gallery slider wrapper -->
When you call flexslider function, use like below
if ($('.g-s-wrapper').length > 0) {
$(window).load(function () {
$('.g-s-wrapper .flexslider').flexslider({
slideshowSpeed: 2000,
directionNav: false,
controlNav: true,
start: function(){
var slide_li = $('.g-s-wrapper ul.slides li').not('.clone');
var control_li = $('.g-s-wrapper .flexslider .flex-control-nav li a');
console.log(control_li);
$.each(slide_li, function(index, el){
var img_src = $('<img src="" />').attr('src', $(el).attr('data-thumb'));
img_src.appendTo(control_li[index]);
});
}
});
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow