触摸滑动简单版

var a;
var aa;
var yy;
var yyy;
document.querySelector("article").style.transform= "translate(0px, 0px)";
document.querySelector("article").addEventListener("touchstart",function(event){
    //console.log(event.changedTouches[0]);
    a=event.changedTouches[0].pageY;
    var r=/\d+/g;
    aa=document.querySelector("article").style.transform.match(r);
    //console.log(aa);
},false);
document.querySelector("article").addEventListener("touchmove",function(event){
    //debugger
    yy = (event.changedTouches[0].pageY)-a;
    yyy=parseFloat(yy)+parseFloat(aa[1]);
    //console.log(yyy);
    document.querySelector("article").style.transform= "translate(0px, "+yyy+"px)";
},false);
document.body.addEventListener("touchmove",function  (event) {
    event.preventDefault();
},false);

你可能感兴趣的:(touch,javascript)