简体   繁体   English

鼠标移动和触摸移动

[英]mousemove and touchmove

I really like this visual effect . 我真的很喜欢这种视觉效果 I want to make this available in iphone or ipad with touchmove. 我想通过touchmove在iPhone或iPad中使用此功能。 Can anyone help me with this? 谁能帮我这个?

This is the JS: 这是JS:

$(document).bind('mousemove',function(e){
    var docW = $(window).width();
    var docH = $(window).height();

    var diffX = (docW/2) - e.clientX;
    var diffY = (docH/2)-100 - e.clientY;

    var dist = distance(docW/2,docH/2, e.clientX, e.clientY);
    var distM = distance(docW/2,(docH/2)+60, e.clientX, e.clientY);

        // eye                          
        var eye_background = Math.floor( diffX /-30 ) +'px '+ Math.floor( diffY /-30 ) +'px';       
        var eye_translate = Math.floor(diffX/-50 )+'px, '+ Math.floor(diffY/-100 )+'px';    
        $(".eye").css({"background-position":eye_background, "-webkit-transform":'translate3d('+eye_translate+',0)',"-moz-transform":'translate('+eye_translate+')',"-o-transform":'translate('+eye_translate+')',"-ms-transform":'translate('+eye_translate+')' });



});

Basically, my question is how can I make this work on apple? 基本上,我的问题是我该如何在Apple上进行这项工作?

You should start a listener on mousedown and stop it on mouseup. 您应该在mousedown上启动一个侦听器,并在mouseup上停止它。 Meanwhile a listener will loop (for example requestanimationfame or setInterval() ) your //eye method. 同时,侦听器将循环//eye方法(例如requestanimationfame或setInterval())

This is a common process in webGL for example. 例如,这是webGL中的常见过程。 example

http://api.jquery.com/mousedown/ http://api.jquery.com/mousedown/

http://api.jquery.com/mouseup/ http://api.jquery.com/mouseup/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM