我正在使用jcarousel插件在同一页面中为每个滑块的外部控件播放多个滑块,但是按下一个控件可以为所有滑块设置动画而不是属于所有滑块! 这里是代码:
<div id="mycarousel">
<ul>
<li>item</li>
<li>item</li>
</ul>
<div class="control">
<a href="#" class="nav_active">1</a>
<a href="#">2</a>
</div>
</div>
<div id="mycarousel_2">
<ul>
<li>item</li>
<li>item</li>
</ul>
<div class="control">
<a href="#" class="nav_active">1</a>
<a href="#">2</a>
</div>
</div>
这里是JS
/**
* We use the initCallback callback
* to assign functionality to the controls
*/
function mycarousel_initCallback(carousel) {
jQuery('.control a').bind('click', function() {
carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
$('.control a').removeClass('nav_active');
$(this).addClass('nav_active');
return false;
});
jQuery('.jcarousel-scroll select').bind('change', function() {
carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
return false;
});
};
// Ride the carousel...
jQuery(document).ready(function() {
jQuery("#mycarousel, #mycarousel_2").jcarousel({
scroll: 1,
animation: 1000,
easing: 'easeOutQuart',
vertical: true,
initCallback: mycarousel_initCallback,
// This tells jCarousel NOT to autobuild prev/next buttons
buttonNextHTML: null,
buttonPrevHTML: null
});
});
如何使每个滑块分别使用自己的控件运行? 感谢
答案 0 :(得分:1)
我有同样的问题,对于第一个轮播我使用了类控制,但是第二个我使用了类control_2。这有助于我
答案 1 :(得分:1)
你可以使用它,它对我有用:
<强> HTML 强>
<div class="carousel_content">
<ul class="mycarousel">
<li>item1</li>
<li>item2</li>
<li>item3</li>
<li>item4</li>
</ul>
<div class="controls">
<a href="#" class="prev">Previous</a>
<a href="#" class="next">Next</a>
</div>
</div>
<div class="carousel_content">
<ul class="mycarousel">
<li>item1</li>
<li>item2</li>
<li>item3</li>
<li>item4</li>
</ul>
<div class="controls">
<a href="#" class="prev">Previous</a>
<a href="#" class="next">Next</a>
</div>
</div>
<强> SCRIPT 强>
(function($){
$('.mycarousel').jcarousel({
scroll: 1,
animation: 1000,
easing: 'easeOutQuart',
vertical: false,
initCallback: mycarousel_initCallback,
buttonNextHTML: null,
buttonPrevHTML: null,
itemLastOutCallback: {
onAfterAnimation: disableCustomButtons
},
itemLastInCallback: {
onAfterAnimation: disableCustomButtons
}
});
function mycarousel_initCallback(carousel) {
var elementPrev = carousel.container.next('.controls').children('.prev');
var elementNext = carousel.container.next('.controls').children('.next');
elementPrev.bind('click', function() {
carousel.prev();
return false;
});
elementNext.bind('click', function() {
carousel.next();
return false;
});
};
function disableCustomButtons(carousel){
var elementPrev = carousel.container.next('.controls').children('.prev');
var elementNext = carousel.container.next('.controls').children('.next');
if (carousel.first == 1) {
elementPrev.addClass('inactive');
} else {
elementPrev.removeClass('inactive');
}
if (carousel.last == carousel.size()) {
elementNext.addClass('inactive');
} else {
elementNext.removeClass('inactive');
}
};
})(jQuery);