zoukankan      html  css  js  c++  java
  • js按钮浮动随手指方向移动而移动

        window.document.getElementById("moveDIV").addEventListener("touchmove", function (event) {
                
                event.preventDefault();
                
                if (event.targetTouches.length == 1) {
                    var touch = event.targetTouches[0];  // 把元素放在手指所在的位置
                 
                    if(touch.pageX + $("#moveDIV").width() > $(window).innerWidth()){
                        
                         window.document.getElementById("moveDIV").style.left = ($(window).innerWidth() - $("#moveDIV").width()) + 'px';
                        
                    }else if(touch.pageX < $("#moveDIV").width()){
                        
                        window.document.getElementById("moveDIV").style.left = 0 + 'px';
                        
                    }else{
                        
                        window.document.getElementById("moveDIV").style.left = touch.pageX + 'px';
                    }
                    
                   if(touch.pageY + $("#moveDIV").height() > $(window).innerHeight()){
                       
                           window.document.getElementById("moveDIV").style.top = ($(window).innerHeight() - $("#moveDIV").height())+ 'px';
                           
                   }else if(touch.pageY < $("#moveDIV").height()){
                        
                        window.document.getElementById("moveDIV").style.top = 0 + 'px';
                        
                    }else {
                       
                           window.document.getElementById("moveDIV").style.top = touch.pageY + 'px';
                           
                   }
                }
            },false)

  • 相关阅读:
    RTC驱动程序分析
    Linux下的RTC子系统
    [置顶] 谈EXPORT_SYMBOL使用
    《Linux内核修炼之道》精华分享与讨论(5)——Kernel地图:Kconfig与Makefile
    写出高效优美的单片机C语言代码
    哈夫曼树
    如何提高浮点数变整数的精度
    CF798C Mike and gcd problem
    CF822C Hacker, pack your bags!
    CF821C Okabe and Boxes
  • 原文地址:https://www.cnblogs.com/myRain/p/6046892.html
Copyright © 2011-2022 走看看