0

我需要将幻灯片效果替换 一张一张幻灯片功能的淡出/淡入效果:

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

请帮我! (对不起,我的英语不好!)

4

5 回答 5

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;
    }
};
于 2009-11-27T14:24:26.057 回答
2

我没有对此进行测试,但我所做的只是将 .animate 函数替换为 .fadeOut 函数。

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;
                        }    
于 2009-08-31T19:45:17.010 回答
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)下一个修改prevnext侧面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
于 2009-08-31T21:08:18.387 回答
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;
            }
        };
    });

如果这有助于解决您的问题,请告诉我。

于 2011-07-25T17:19:33.433 回答
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;                            

我希望这可以帮助别人 :)

于 2010-06-29T17:39:45.040 回答