首页 新闻 会员 周边

鼠标事件怎么转换成手机事件?

0
[待解决问题]

var imgL=$(".pic img").size();
var deg=360/imgL;
var roY=0,roX=-10;
var xN=0,yN=0;
var play=null;

$(".pic img").each(function(i){
$(this).css({"transform":"rotateY("+i*deg+"deg) translateZ(300px)"});
$(this).attr('ondragstart','return false');
});

$(document).mousedown(function(ev){
var x_=ev.clientX;
var y_=ev.clientY;
clearInterval(play);
console.log('我按下了');
$(this).bind('mousemove',function(ev){
/*获取当前鼠标的坐标*/
var x=ev.clientX;
var y=ev.clientY;
/*两次坐标之间的距离*/
xN=x-x_;
yN=y-y_;

roY+=xN*0.2;
roX-=yN*0.1;
console.log('移动');
//$('body').append('<div style="width:5px;height:5px;position:absolute;top:'+y+'px;left:'+x+'px;background-color:red"></div>');

$('.pic').css({
transform:'perspective(800px) rotateX('+roX+'deg) rotateY('+roY+'deg)'
});
/*之前的鼠标坐标*/
x_=ev.clientX;
y_=ev.clientY;

});
}).mouseup(function(){
$(this).unbind('mousemove');
var play=setInterval(function(){

xN*=0.95;
yN*=0.95
if(Math.abs(xN)<1 && Math.abs(yN)<1){
clearInterval(play);
}
roY+=xN*0.2;
roX-=yN*0.1;
$('.pic').css({
transform:'perspective(800px) rotateX('+roX+'deg) rotateY('+roY+'deg)'
});

},30);

});


这段代码在手机上怎么实现?

lijing297的主页 lijing297 | 菜鸟二级 | 园豆:223
提问于:2017-06-28 20:42
< >
分享
所有回答(1)
0


var tool= {
//移动端点击事件click 有300ms 的延迟
tap : function(obj,callback){

if(typeof obj == "object"){

var startTime = 0;
var isMove = false;

obj.addEventListener('touchstart',function(){
startTime = Date.now()
})

obj.addEventListener('touchmove',function(){
isMove =true
})

obj.addEventListener('touchend',function(ev){

})
}

}

}

 

基本就是这个样子

老年游侠 | 园豆:364 (菜鸟二级) | 2017-06-28 23:55
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册