我正在尝试创建一个包含3个div的图库,其中包含已同步的滑块(主图像,缩略图轮播和文本信息)。使用'as navfor'和'sync'函数我可以完成所有工作,除非单击图像缩略图时文本信息不与JS同步:
<script type="text/javascript">
$(window).load(function() {
// The slider being synced must be initialized first
$('#carousel').flexslider({
animation: "slide",
controlNav: false,
animationLoop: true,
slideshow: false,
itemWidth: 233,
itemMargin: 5,
asNavFor: '#slider'
});
$('#info').flexslider({
animation: "fade",
controlNav: false,
directionNav: false,
animationLoop: true,
slideshow: false,
sync: "#carousel",
});
$('#slider').flexslider({
animation: "slide",
controlNav: false,
animationLoop: true,
slideshow: false,
sync: "#info",
});
});
</script>
所以基本上我想让#carousel'asNavFor'同时是#slider和#info。如果我单独添加两个,那么第二个取代第一个。逗号分开也不起作用。最小的JS知识。 任何帮助非常感谢...
答案 0 :(得分:1)
检查下面链接问题的第二个回复。作者声称该代码可用于同步2个或更多滑块。我的第一枪就失败了,但我仍然希望它有效。
Flex Slider - How to add same controls for two sliders
我会在这里重新发布他的代码:
HTML:
<div id="main-slider" class="flexslider">
<ul class="slides">
<li><img src="image1.jpg" /></li>
<li><img src="image2.jpg" /></li>
<li><img src="image3.jpg" /></li>
<li><img src="image4.jpg" /></li>
</ul>
</div>
<div class="flexslider_children">
<ul class="slides">
<li><p>Text 1</p></li>
<li><p>Text 2</p></li>
<li><p>Text 3</p></li>
<li><p>Text 4</p></li>
</ul>
</div>
<div class="flexslider_children">
<ul class="slides">
<li><p>Text 1</p></li>
<li><p>Text 2</p></li>
<li><p>Text 3</p></li>
<li><p>Text 4</p></li>
</ul>
</div>
Javascript:
/**
* Create the children flexsliders. Must be array of jquery objects with the
* flexslider data. Easiest way is to place selector group in a var.
*/
var children_slides = $('.flexslider_children').flexslider({
'slideshow': false, // Remove the animations
'controlNav' : false // Remove the controls
});
/**
* Set up the main flexslider
*/
$('.flexslider').flexslider({
'pauseOnHover' : true,
'animationSpeed': 2000,
'slideshowSpeed': 5000,
'initDelay': 3000,
// Call the update_children_slides which itterates through all children slides
'before' : function(slider){ // Hijack the flexslider
update_children_slides(slider.animatingTo);
}
});
/**
* Method that updates children slides
* fortunately, since all the children are not animating,
* they will only update if the main flexslider updates.
*/
function update_children_slides (slide_number){
// Iterate through the children slides but not past the max
for (i=0;i<children_slides.length;i++) {
// Run the animate method on the child slide
$(children_slides[i]).data('flexslider').flexAnimate(slide_number);
}
}