一陀牛屎 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 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算