一陀牛屎 2016-01-02 13:50 采纳率: 0%
浏览 2413

html5 js和css3问题滑动第一次没有效果第二次才出来

js加css3实现动画问题。。
javascript函数css3动画html5
第一个::::
function slideList(){
var downY = 0;
var step = 1/4;
var nowIndex = 0;
var nextorprevIndex = 0;
$li.on('touchstart',function(ev){
var touch = ev.originalEvent.changedTouches[0];
downY = touch.pageY;
nowIndex = $(this).index();
$li.on('touchmove',function(ev){
var touch = ev.originalEvent.changedTouches[0];

        $(this).siblings().hide();

        if( touch.pageY < downY ){  //↑
            nextorprevIndex = nowIndex == $li.length-1 ? 0 : nowIndex + 1;
            $li.eq(nextorprevIndex).css('transform','translate(0,'+(viewHeight + touch.pageY - downY)+'px)');
        }
        else if( touch.pageY > downY ){  
            nextorprevIndex = nowIndex == 0 ? $li.length-1 : nowIndex - 1;
            $li.eq(nextorprevIndex).css('transform','translate(0,'+(-viewHeight + touch.pageY - downY)+'px)');
        }

        $li.eq(nextorprevIndex).show().addClass('zIndex');
        $(this).css('transform','translate(0,'+(touch.pageY - downY)*step+'px) scale('+(1-Math.abs(touch.pageY - downY)/viewHeight*step)+')');

    });

    $li.on('touchend',function(ev){
        var touch = ev.originalEvent.changedTouches[0];
        if( touch.pageY < downY ){  
            $(this).css('transform','translate(0,'+(-viewHeight * step)+'px) scale('+(1-step)+')');
        }
        else if( touch.pageY > downY ){  
            $(this).css('transform','translate(0,'+(viewHeight * step)+'px) scale('+(1-step)+')');
        }
        $(this).css('transition','.3s');
        $li.eq(nextorprevIndex).css('transform','translate(0,0)');
        $li.eq(nextorprevIndex).css('transition','.3s');
    });

});

$li.on('transitionEnd webkitTransitionEnd',function(ev){
    resetFn();

});

function resetFn(){
    $li.css('transition','');
    $li.eq(nextorprevIndex).removeClass('zIndex').siblings().hide();
}

}
第二个;;::
function slideList(){
var downY=0;
var step=1/4;
var nowIndex=0;
var nextIndex=0;

$li.on('touchstart',function(ev){
    var touch = ev.originalEvent.changedTouches[0];
    nowIndex=$(this).index();
    downY=touch.pageY;
    $li.on('touchmove',function(ev){
        var touch = ev.originalEvent.changedTouches[0];
            $(this).siblings().hide();
            if(downY>touch.pageY){
                nextIndex= nowIndex == $li.length-1 ? 0 : nowIndex+1;
                $li.eq(nextIndex).css('transform','translate(0,'+(viewHeight + touch.pageY - downY)+'px');
            }else if(downY<touch.pageY){
                nextIndex=nowIndex==0 ? $li.length-1 : nowIndex-1;
                $li.eq(nextIndex).css('transform','translate(0,'+(-viewHeight+touch.pageY-downY)+'px');
            }
            $li.eq(nextIndex).show().addClass("zIndex");
            $(this).css('transform','translate(0,'+(touch.pageY-downY)*step+'px) scale('+(1-Math.abs(touch.pageY-downY)/viewHeight*step)+')');
    })

    $li.on('touchend',function(ev){
        var touch = ev.originalEvent.changedTouches[0];
            if(downY>touch.pageY){
                $(this).css('transform','translate(0,'+(-viewHeight*step)+'px) scale('+(1-step)+')');
            }else if(downY<touch.pageY){
                $(this).css('transform','translate(0,'+(viewHeight*step)+'px) scale('+(1-step)+')');
            }
            $(this).css('transition','0.3s');
            $li.eq(nextIndex).css('transform','translate(0,0)');
            $li.eq(nextIndex).css('transition','0.3s');
    })
})
$li.on('transitionEnd webkitTransitionEnd',function(ev){
        reswtFn();
    })
function reswtFn(){
    $li.css('transition','');
    $li.eq(nextIndex).removeClass('zIndex').siblings().hide();
}

}
效果为什么第二个不行????????第一个可以???????、

  • 写回答

1条回答 默认 最新

  • devmiao 2016-01-02 15:23
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器