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)

  • 相关阅读:
    Linux
    Linux -- 文件统计常用命令
    再论最小二乘
    再论EM算法的收敛性和K-Means的收敛性
    【MySQL】优化—工欲善其事,必先利其器之EXPLAIN
    【Linux】浅谈段页式内存管理
    【Linux】之系统工具top
    【Linux】之shell特殊变量整理
    【Linux】系统 之 RAID
    【MySQL】binlog缓存的问题和性能
  • 原文地址:https://www.cnblogs.com/myRain/p/6046892.html
Copyright © 2011-2022 走看看