我需要在上一页上替换幻灯片效果 淡出/淡入效果 em> next 幻灯片功能:
function animate(dir,clicked){
u = true;
switch(dir){
case 'next':
t = t+1;
m = (-(t*w-w));
current(t);
if(o.autoHeight){autoHeight(t);}
if(s<3){
if (t===3){$(o.slides,obj).children(':eq(0)').css({left:(s*w)});}
if (t===2){$(o.slides,obj).children(':eq('+(s-1)+')').css({position:'absolute',left:(w)});}
}
$(o.slides,obj).animate({left: m}, o.slidespeed,function(){
if (t===s+1) {
t = 1;
$(o.slides,obj).css({left:0},function(){$(o.slides,obj).animate({left:m})});
$(o.slides,obj).children(':eq(0)').css({left: 0});
$(o.slides,obj).children(':eq('+(s-1)+')').css({ position:'absolute',left:-w});
}
if (t===s) $(o.slides,obj).children(':eq(0)').css({left:(s*w)});
if (t===s-1) $(o.slides,obj).children(':eq('+(s-1)+')').css({left:s*w-w});
u = false;
});
break;
case 'prev':
t = t-1;
m = (-(t*w-w));
current(t);
if(o.autoHeight){autoHeight(t);}
if (s<3){
if(t===0){$(o.slides,obj).children(':eq('+(s-1)+')').css({position:'absolute',left:(-w)});}
if(t===1){$(o.slides,obj).children(':eq(0)').css({position:'absolute',left:0});}
}
$(o.slides,obj).animate({left: m}, o.slidespeed,function(){
if (t===0) {
t = s;
$(o.slides,obj).children(':eq('+(s-1)+')').css({position:'absolute',left:(s*w-w)});
$(o.slides,obj).css({left: -(s*w-w)});
$(o.slides,obj).children(':eq(0)').css({left:(s*w)});
}
if (t===2 ) $(o.slides,obj).children(':eq(0)').css({position:'absolute',left:0});
if (t===1) $(o.slides,obj).children(':eq('+ (s-1) +')').css({position:'absolute',left:-w});
u = false;
});
break;
case 'fade':
t = [t]*1;
m = (-(t*w-w));
current(t);
if(o.autoHeight){autoHeight(t);}
$(o.slides,obj).children().fadeOut(o.fadespeed, function(){
$(o.slides,obj).css({left: m});
$(o.slides,obj).children(':eq('+(s-1)+')').css({left:s*w-w});
$(o.slides,obj).children(':eq(0)').css({left:0});
if(t===s){$(o.slides,obj).children(':eq(0)').css({left:(s*w)});}
if(t===1){$(o.slides,obj).children(':eq('+(s-1)+')').css({ position:'absolute',left:-w});}
$(o.slides,obj).children().fadeIn(o.fadespeed);
u = false;
});
break;
default:
break;
}
};
我曾尝试过,但自动重启不起作用!
您可以查看文档,并使用此链接中的示例下载完整代码: http://github.com/nathansearles/loopedSlider/tree/master
请帮帮我! (抱歉我的英文不好!)
答案 0 :(得分:2)
我没有对此进行测试,但我所做的只是用.fadeOut函数替换.animate函数。
function animate(dir,clicked){
u = true;
switch(dir){
case 'next':
t = t+1;
m = (-(t*w-w));
current(t);
if(o.autoHeight){autoHeight(t);}
if(s<3){
if (t===3){$(o.slides,obj).children(':eq(0)').css({left:(s*w)});}
if (t===2){$(o.slides,obj).children(':eq('+(s-1)+')').css({position:'absolute',left:(w)});}
}
$(o.slides,obj).fadeOut(o.fadespeed ,function(){
if (t===s+1) {
t = 1;
$(o.slides,obj).css({left:0},function(){$(o.slides,obj).animate({left:m})});
$(o.slides,obj).children(':eq(0)').css({left: 0});
$(o.slides,obj).children(':eq('+(s-1)+')').css({ position:'absolute',left:-w});
}
if (t===s) $(o.slides,obj).children(':eq(0)').css({left:(s*w)});
if (t===s-1) $(o.slides,obj).children(':eq('+(s-1)+')').css({left:s*w-w});
u = false;
});
break;
case 'prev':
t = t-1;
m = (-(t*w-w));
current(t);
if(o.autoHeight){autoHeight(t);}
if (s<3){
if(t===0){$(o.slides,obj).children(':eq('+(s-1)+')').css({position:'absolute',left:(-w)});}
if(t===1){$(o.slides,obj).children(':eq(0)').css({position:'absolute',left:0});}
}
$(o.slides,obj).fadeOut(o.fadespeed ,function(){
if (t===0) {
t = s;
$(o.slides,obj).children(':eq('+(s-1)+')').css({position:'absolute',left:(s*w-w)});
$(o.slides,obj).css({left: -(s*w-w)});
$(o.slides,obj).children(':eq(0)').css({left:(s*w)});
}
if (t===2 ) $(o.slides,obj).children(':eq(0)').css({position:'absolute',left:0});
if (t===1) $(o.slides,obj).children(':eq('+ (s-1) +')').css({position:'absolute',left:-w});
u = false;
});
break;
case 'fade':
t = [t]*1;
m = (-(t*w-w));
current(t);
if(o.autoHeight){autoHeight(t);}
$(o.slides,obj).children().fadeOut(o.fadespeed, function(){
$(o.slides,obj).css({left: m});
$(o.slides,obj).children(':eq('+(s-1)+')').css({left:s*w-w});
$(o.slides,obj).children(':eq(0)').css({left:0});
if(t===s){$(o.slides,obj).children(':eq(0)').css({left:(s*w)});}
if(t===1){$(o.slides,obj).children(':eq('+(s-1)+')').css({ position:'absolute',left:-w});}
$(o.slides,obj).children().fadeIn(o.fadespeed);
u = false;
});
break;
default:
break;
}
答案 1 :(得分:2)
1)我引入了一个变量来跟踪我们展示内容的容器的左侧:
//these are default options just declare our variable below these
var n = 0;
var interval=0;
var restart=0;
var cLeft = $(o.container).position().left+'px';//Left of Container
2)接下来修改prev
一面声明中的next
和switch
函数:
function animate(dir,clicked){
u = true;
switch(dir){
case 'next':
t = t+1;
m = (-(t*w-w));
current(t);
if(o.autoHeight){autoHeight(t);}
var pre=0;
if(t===s+1){t = 1; }
if(t===1){ pre=s; }
else{ pre = t-1; }
$(o.slides,obj).children(':eq(' + (pre-1) + ')')
.css({position:'absolute',left:cLeft,'z-index':'1'})
.fadeOut('slow');
$(o.slides,obj).children(':eq(' + (t-1) + ')')
.css({position:'absolute',left:cLeft,'z-index':'500'})
.fadeIn('slow');
u = false;
break;
case 'prev':
t = t-1;
m = (-(t*w-w));
current(t);
if(o.autoHeight){autoHeight(t);}
var pre=1;
if(t===0){ t = s; }
else{ pre = t+1; }
$(o.slides,obj).children(':eq(' + (pre-1) + ')')
.css({position:'absolute',left:cLeft,'z-index':'1'})
.fadeOut('slow'); //FADEOUT CURRENT IMAGE
$(o.slides,obj).children(':eq(' + (t-1) + ')')
.css({position:'absolute',left:cLeft,'z-index':'500'})
.fadeIn('slow');//FADEIN NEXT ONE
u = false;
break;
//....
//....rest of the stuff which you can modify like this
答案 2 :(得分:2)
这很容易编辑。
function animate(dir, clicked) {
u = true;
switch (dir) {
case 'next':
animate('fade', t);
t = t + 1;
m = (-(t * w - w));
current(t);
if (t === s) { t = 0; }
/* -- don't used this script
//-- none slide last image is map
if (o.autoHeight) { autoHeight(t); }
$(o.slides, obj).animate({ left: m }, o.slidespeed, function() {
if ((t === s + 1)) {
t = 1;
$(o.slides, obj).css({ left: 0 }, function() { $(o.slides, obj).animate({ left: m }) });
$(o.slides, obj).children(':eq(0)').css({ left: 0 });
$(o.slides, obj).children(':eq(' + (s - 1) + ')').css({ position: 'absolute', left: -w });
}
if (t === s) $(o.slides, obj).children(':eq(0)').css({ left: (s * w) });
if (t === s - 1)//$(o.slides, obj).children(':eq(0)').css({ left: (s * w) });
{
$(o.slides, obj).children(':eq(' + (s - 1) + ')').css({ left: s * w - w });
}
u = false;
});
*/
break;
case 'prev':
animate('fade', t);
t = t - 1;
m = (-(t * w - w));
current(t);
/* -- don't used this script
if (o.autoHeight) { autoHeight(t); }
$(o.slides, obj).animate({ left: m }, o.slidespeed, function() {
if (t === 0) {
t = s;
$(o.slides, obj).children(':eq(' + (s - 1) + ')').css({ position: 'absolute', left: (s * w - w) });
$(o.slides, obj).css({ left: -(s * w - w) });
$(o.slides, obj).children(':eq(0)').css({ left: (s * w) });
}
if (t === 2) $(o.slides, obj).children(':eq(0)').css({ position: 'absolute', left: 0 });
if (t === 1) $(o.slides, obj).children(':eq(' + (s - 1) + ')').css({ position: 'absolute', left: -w });
u = false;
});
*/
break;
case 'fade':
t = [t] * 1;
m = (-(t * w - w));
current(t);
if (o.autoHeight) { autoHeight(t); }
$(o.slides, obj).children().fadeOut(o.fadespeed, function() {
$(o.slides, obj).css({ left: m });
$(o.slides, obj).children(':eq(' + (s - 1) + ')').css({ left: s * w - w });
$(o.slides, obj).children(':eq(0)').css({ left: 0 });
if (t === s) { $(o.slides, obj).children(':eq(0)').css({ left: (s * w) }); }
if (t === 1) { $(o.slides, obj).children(':eq(' + (s - 1) + ')').css({ position: 'absolute', left: -w }); }
$(o.slides, obj).children().fadeIn(o.fadespeed);
u = false;
});
break;
default:
break;
}
};
答案 3 :(得分:1)
我使用了以下代码,这似乎对我有用:
case "next":
times = times+1;
distance = (-(times*width-width));
current(times);
if(o.autoHeight){autoHeight(times);}
$(o.slides,$t).children().fadeOut(o.fadespeed, function(){
$(o.slides,$t).css({left: distance});
$(o.slides,$t).children(":eq("+(slides-1)+")").css({left:slides*width-width});
$(o.slides,$t).children(":eq(0)").css({left:0});
if(times===slides+1){
times = 1;
distance = (-(times*width-width));
current(times);
}
if(times===slides)
{$(o.slides,$t).children(":eq(0)").css({left:(slides*width)});}
if(times===slides-1)
{$(o.slides,$t).children(":eq("+(slides-1)+")").css({ position:"absolute",left:-width});}
$(o.slides,$t).children().fadeIn(o.fadespeed);
active = false;;
});
break;
我希望这有助于某人:)
答案 4 :(得分:1)
这是我的代码版本。这会将默认幻灯片效果更改为淡入/淡出效果。我正在使用loopedSlider 0.5.5 - jQuery插件。自动启动功能也完美运行。您会注意到下面有重复的代码行。你可以自己轻松解决这个问题。
function animate(dir,clicked){
active = true;
switch(dir){
case "next":
if(times>slides-1){ times = 0; }
times = times+1;
distance = (-(times*width-width));
current(times);
if(o.autoHeight){autoHeight(times);}
$(o.slides,obj).children().fadeOut(o.fadespeed, function(){
$(o.slides,obj).css({left: distance});
$(o.slides,obj).children(":eq("+(slides-1)+")").css({left:slides*width-width});
$(o.slides,obj).children(":eq(0)").css({left:0});
if(times===slides){$(o.slides,obj).children(":eq(0)").css({left:(slides*width)});}
if(times===1){$(o.slides,obj).children(":eq("+(slides-1)+")").css({ position:"absolute",left:-width});}
$(o.slides,obj).children().fadeIn(o.fadespeed);
active = false;
});
break;
case "prev":
if(times==1){ times = slides+1; }
times = times-1;
distance = (-(times*width-width));
current(times);
if(o.autoHeight){autoHeight(times);}
$(o.slides,obj).children().fadeOut(o.fadespeed, function(){
$(o.slides,obj).css({left: distance});
$(o.slides,obj).children(":eq("+(slides-1)+")").css({left:slides*width-width});
$(o.slides,obj).children(":eq(0)").css({left:0});
if(times===slides){$(o.slides,obj).children(":eq(0)").css({left:(slides*width)});}
if(times===1){$(o.slides,obj).children(":eq("+(slides-1)+")").css({ position:"absolute",left:-width});}
$(o.slides,obj).children().fadeIn(o.fadespeed);
active = false;
});
break;
case "fade":
times = [times]*1;
distance = (-(times*width-width));
current(times);
if(o.autoHeight){autoHeight(times);}
$(o.slides,obj).children().fadeOut(o.fadespeed, function(){
$(o.slides,obj).css({left: distance});
$(o.slides,obj).children(":eq("+(slides-1)+")").css({left:slides*width-width});
$(o.slides,obj).children(":eq(0)").css({left:0});
if(times===slides){$(o.slides,obj).children(":eq(0)").css({left:(slides*width)});}
if(times===1){$(o.slides,obj).children(":eq("+(slides-1)+")").css({ position:"absolute",left:-width});}
$(o.slides,obj).children().fadeIn(o.fadespeed);
active = false;
});
break;
default:
break;
}
};
});
请告诉我这是否有助于解决您的问题。