移动端,滑动屏幕

//屏幕呈现的三个屏
let first=document.querySelector('.div-first-page')
let second=document.querySelector('.div-second-page')
let third=document.querySelector('.div-third-page')

//添加事件方法,target:时间目标,down:往下滑,up:往上滑。
let move=0
let start=0
let end=0
let addEvent=(target,down,up)=>{
    target.addEventListener('touchstart',(e1)=>{
        start=e1.changedTouches[0].screenY
        target.addEventListener('touchend',(e2)=>{
            end=e2.changedTouches[0].screenY
            move=start-end
            if(move>50){
                down()
            }
            if(move<-50){
                up()
            }
            start=end
            move=0
        })
    })
}
//呈现第一个
let presentF=()=>{
    first.style.top='0'
    second.style.top='100vh'
    third.style.top='200vh' 
}
//呈现第二个
let presentS=()=>{
    first.style.top='-100vh'
    second.style.top='0'
    third.style.top='100vh'  
}
//呈现第三个
let presentT=()=>{
    first.style.top='-200vh'
    second.style.top='-100vh'
    third.style.top='0'  
}
//给三个屏绑定事件
addEvent(first,presentS,()=>{})
addEvent(second,presentT,presentF)
addEvent(third,()=>{},presentS)

猜你喜欢

转载自blog.csdn.net/weixin_42029487/article/details/86605424