我正在使用jCarousel插件(http://sorgalla.com/projects/jcarousel/),但是我希望图片不是像“自动滚动旋转木马”演示中那样滑动,而是淡入淡出。使用的是一个自动滚动的jCarousel,一次只显示一个元素。但是我查看了Cycle插件,似乎不能满足我的需求,因为我想要显示的元素包含文本和图像。
感谢任何能够帮助我的人。
Phil
感谢任何能够帮助我的人。
Phil
即使jCarousel只知道滚动幻灯片,您仍然可以模拟淡出效果:
$('#yourContainer').jcarousel({
visible: 1,
scroll: 1,
itemLoadCallback: {
onBeforeAnimation: mycarousel_fadeOut,
onAfterAnimation: mycarousel_fadeIn
}
});
function mycarousel_fadeOut(carousel) {
var JCcontainer = carousel.clip.context;
$(JCcontainer).fadeOut();
}
function mycarousel_fadeIn(carousel) {
var JCcontainer = carousel.clip.context;
$(JCcontainer).fadeIn();
}
试试这个:
var jcarousel = $('#yourContainer');
jcarousel.jcarousel({
animation: {
duration: 0 // make changing image immediately
}
});
// make fadeIn effect
jcarousel.on('jcarousel:animate', function (event, carousel) {
$(carousel._element.context).find('li').hide().fadeIn(1000);
});
将函数更改为这个可以工作,有点效果(您可能仍会看到滚动):
function mycarousel_fadeOut(carousel) {
var JCcontainer = carousel.clip.context;
$(JCcontainer).fadeOut();
}
function mycarousel_fadeIn(carousel) {
var JCcontainer = carousel.clip.context;
$(JCcontainer).fadeIn();
}
var mycarousel_fadeOut = function(carousel, state) {
if (state !== "init") {
$(carousel.clip.context).find('img').fadeOut(800);
}
};
var mycarousel_fadeIn = function(carousel, state) {
if (state !== "init") {
$(carousel.clip.context).find('img').fadeIn(800);
}
};
var carousel = $('.jcarousel').jcarousel({
list : '.items',
items : '.i',
wrap : 'both', // for good measure
animation: {
duration: 0 // swap slides immediately
}
}).jcarouselAutoscroll({
interval: 1000 * 5,
target: '+=1',
autostart: true
});
// fade hack
carousel.jcarousel('items').hide();
carousel.jcarousel('first').show();
carousel.on('jcarousel:visiblein', function(event, carousel) {
$(event.target).fadeIn();
});
carousel.on('jcarousel:visibleout', function(event, carousel) {
$(event.target).fadeOut();
carousel._trigger('animateend'); // the event doesn't fire when items are positioned absolutely (so autoscroll wouldn't work), fire manually
});
.items {height: 450px;}
.i {position: absolute;}