admin管理员组文章数量:1026912
I'm using the jquery plugin Flexslider. I'm using the carousel as navigation for the slider. I'm trying to add a css class "active" to the first carousel element when the page loads, then remove the "active" class from the first element as the user chooses another element and add the "active" class to the next element the user chooses.
The carousel was working fine as a navigation, but when I used the "start function" in the carousel to add the active class as suggested below, the slider stops moving and just stays on one slide. It's strange it will work for 3-4 clicks and then won't keep moving...
Ideas?
Javascript
<script type="text/javascript" charset="utf-8">
$(window).load(function() {
// The slider being synced must be initialized first
$('#clientthumbs').flexslider({
animation: "slide",
controlNav: false,
animationLoop: true,
directionNav: true,
slideshow: false,
itemWidth: 210,
itemMargin: 20,
asNavFor: '#clienttestimonials',
start : function(slider) {
$('#clientthumbs li').click(function(event) {
event.preventDefault();
$('#clientthumbs li').removeClass('active');
$(this).addClass('active');
$('.flexslider').show();
var slideTo = $(this).attr("rel"); //Grab rel value from link;
var slideToInt = parseInt(slideTo);
if (slider.currentSlide != slideToInt) {
$(this).addClass('active');
slider.flexAnimate(slideToInt) //Move the slider to the correct slide (Unless the slider is also already showing the slide we want);
}
});
}
});
$('#clienttestimonials').flexslider({
animation: "slide",
controlNav: false,
directionNav: false,
animationLoop: false,
slideshow: false,
sync: "#clientthumbs"
});
});
</script>
HTML
<div id="clientthumbs" class="flexslider">
<ul class="slides">
<li class="client1"></li>
<li class="client2"></li>
</ul>
</div>
<div id="clienttestimonials" class="flexslider">
<ul class="slides">
<li>
<div class="clientpicsandquotes">
</div>
</li>
<li>
<div class="clientpicsandquotes">
</div>
</li>
</ul>
</div>
I'm using the jquery plugin Flexslider. I'm using the carousel as navigation for the slider. I'm trying to add a css class "active" to the first carousel element when the page loads, then remove the "active" class from the first element as the user chooses another element and add the "active" class to the next element the user chooses.
The carousel was working fine as a navigation, but when I used the "start function" in the carousel to add the active class as suggested below, the slider stops moving and just stays on one slide. It's strange it will work for 3-4 clicks and then won't keep moving...
Ideas?
Javascript
<script type="text/javascript" charset="utf-8">
$(window).load(function() {
// The slider being synced must be initialized first
$('#clientthumbs').flexslider({
animation: "slide",
controlNav: false,
animationLoop: true,
directionNav: true,
slideshow: false,
itemWidth: 210,
itemMargin: 20,
asNavFor: '#clienttestimonials',
start : function(slider) {
$('#clientthumbs li').click(function(event) {
event.preventDefault();
$('#clientthumbs li').removeClass('active');
$(this).addClass('active');
$('.flexslider').show();
var slideTo = $(this).attr("rel"); //Grab rel value from link;
var slideToInt = parseInt(slideTo);
if (slider.currentSlide != slideToInt) {
$(this).addClass('active');
slider.flexAnimate(slideToInt) //Move the slider to the correct slide (Unless the slider is also already showing the slide we want);
}
});
}
});
$('#clienttestimonials').flexslider({
animation: "slide",
controlNav: false,
directionNav: false,
animationLoop: false,
slideshow: false,
sync: "#clientthumbs"
});
});
</script>
HTML
<div id="clientthumbs" class="flexslider">
<ul class="slides">
<li class="client1"></li>
<li class="client2"></li>
</ul>
</div>
<div id="clienttestimonials" class="flexslider">
<ul class="slides">
<li>
<div class="clientpicsandquotes">
</div>
</li>
<li>
<div class="clientpicsandquotes">
</div>
</li>
</ul>
</div>
Share
Improve this question
edited Jan 31, 2013 at 20:43
DaveG
asked Jan 16, 2013 at 18:58
DaveGDaveG
1,2032 gold badges26 silver badges45 bronze badges
2
- Are you showing one image at a time in your slider? In that case, there is no need to add active class as there is already one provided in the FlexSlider itself.. Is that the case or is it different? – mabus44 Commented Jan 16, 2013 at 19:09
- No I'm trying to change the class of the one of the carousel images which shows multiple images at once. The carousel is acting as navigation to the slider – DaveG Commented Jan 16, 2013 at 19:11
1 Answer
Reset to default 2Try adding a rel tag to the #clientthumbs li items and the #clienttestimonials li items and make sure they match. Then replace your start function with:
start : function(slider) {
$('#clientthumbs li').click(function(event) {
event.preventDefault();
$('#clientthumbs li').removeClass('active');
$(this).addClass('active');
$('.flexslider').show();
var slideTo = $(this).attr("rel"); //Grab rel value from link;
var slideToInt = parseInt(slideTo);
if (slider.currentSlide != slideToInt) {
$(this).addClass('active');
slider.flexAnimate(slideToInt) //Move the slider to the correct slide (Unless the slider is also already showing the slide we want);
}
}
});
I'm using the jquery plugin Flexslider. I'm using the carousel as navigation for the slider. I'm trying to add a css class "active" to the first carousel element when the page loads, then remove the "active" class from the first element as the user chooses another element and add the "active" class to the next element the user chooses.
The carousel was working fine as a navigation, but when I used the "start function" in the carousel to add the active class as suggested below, the slider stops moving and just stays on one slide. It's strange it will work for 3-4 clicks and then won't keep moving...
Ideas?
Javascript
<script type="text/javascript" charset="utf-8">
$(window).load(function() {
// The slider being synced must be initialized first
$('#clientthumbs').flexslider({
animation: "slide",
controlNav: false,
animationLoop: true,
directionNav: true,
slideshow: false,
itemWidth: 210,
itemMargin: 20,
asNavFor: '#clienttestimonials',
start : function(slider) {
$('#clientthumbs li').click(function(event) {
event.preventDefault();
$('#clientthumbs li').removeClass('active');
$(this).addClass('active');
$('.flexslider').show();
var slideTo = $(this).attr("rel"); //Grab rel value from link;
var slideToInt = parseInt(slideTo);
if (slider.currentSlide != slideToInt) {
$(this).addClass('active');
slider.flexAnimate(slideToInt) //Move the slider to the correct slide (Unless the slider is also already showing the slide we want);
}
});
}
});
$('#clienttestimonials').flexslider({
animation: "slide",
controlNav: false,
directionNav: false,
animationLoop: false,
slideshow: false,
sync: "#clientthumbs"
});
});
</script>
HTML
<div id="clientthumbs" class="flexslider">
<ul class="slides">
<li class="client1"></li>
<li class="client2"></li>
</ul>
</div>
<div id="clienttestimonials" class="flexslider">
<ul class="slides">
<li>
<div class="clientpicsandquotes">
</div>
</li>
<li>
<div class="clientpicsandquotes">
</div>
</li>
</ul>
</div>
I'm using the jquery plugin Flexslider. I'm using the carousel as navigation for the slider. I'm trying to add a css class "active" to the first carousel element when the page loads, then remove the "active" class from the first element as the user chooses another element and add the "active" class to the next element the user chooses.
The carousel was working fine as a navigation, but when I used the "start function" in the carousel to add the active class as suggested below, the slider stops moving and just stays on one slide. It's strange it will work for 3-4 clicks and then won't keep moving...
Ideas?
Javascript
<script type="text/javascript" charset="utf-8">
$(window).load(function() {
// The slider being synced must be initialized first
$('#clientthumbs').flexslider({
animation: "slide",
controlNav: false,
animationLoop: true,
directionNav: true,
slideshow: false,
itemWidth: 210,
itemMargin: 20,
asNavFor: '#clienttestimonials',
start : function(slider) {
$('#clientthumbs li').click(function(event) {
event.preventDefault();
$('#clientthumbs li').removeClass('active');
$(this).addClass('active');
$('.flexslider').show();
var slideTo = $(this).attr("rel"); //Grab rel value from link;
var slideToInt = parseInt(slideTo);
if (slider.currentSlide != slideToInt) {
$(this).addClass('active');
slider.flexAnimate(slideToInt) //Move the slider to the correct slide (Unless the slider is also already showing the slide we want);
}
});
}
});
$('#clienttestimonials').flexslider({
animation: "slide",
controlNav: false,
directionNav: false,
animationLoop: false,
slideshow: false,
sync: "#clientthumbs"
});
});
</script>
HTML
<div id="clientthumbs" class="flexslider">
<ul class="slides">
<li class="client1"></li>
<li class="client2"></li>
</ul>
</div>
<div id="clienttestimonials" class="flexslider">
<ul class="slides">
<li>
<div class="clientpicsandquotes">
</div>
</li>
<li>
<div class="clientpicsandquotes">
</div>
</li>
</ul>
</div>
Share
Improve this question
edited Jan 31, 2013 at 20:43
DaveG
asked Jan 16, 2013 at 18:58
DaveGDaveG
1,2032 gold badges26 silver badges45 bronze badges
2
- Are you showing one image at a time in your slider? In that case, there is no need to add active class as there is already one provided in the FlexSlider itself.. Is that the case or is it different? – mabus44 Commented Jan 16, 2013 at 19:09
- No I'm trying to change the class of the one of the carousel images which shows multiple images at once. The carousel is acting as navigation to the slider – DaveG Commented Jan 16, 2013 at 19:11
1 Answer
Reset to default 2Try adding a rel tag to the #clientthumbs li items and the #clienttestimonials li items and make sure they match. Then replace your start function with:
start : function(slider) {
$('#clientthumbs li').click(function(event) {
event.preventDefault();
$('#clientthumbs li').removeClass('active');
$(this).addClass('active');
$('.flexslider').show();
var slideTo = $(this).attr("rel"); //Grab rel value from link;
var slideToInt = parseInt(slideTo);
if (slider.currentSlide != slideToInt) {
$(this).addClass('active');
slider.flexAnimate(slideToInt) //Move the slider to the correct slide (Unless the slider is also already showing the slide we want);
}
}
});
本文标签: javascriptJquery Flexslider Add and Remove Class on Slide ChangeStack Overflow
版权声明:本文标题:javascript - Jquery Flexslider Add and Remove Class on Slide Change - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745653103a2161434.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论