<html> <head> <meta charset="UTF-8"> <style type="text/Css"> body{background-color:#000000;} .window{position:absolute;z-index:1;overflow:hidden;width:600px;height:400px;background-color:red;left: 0px;} .dragme{position:relative;background-image:url('img/testbg.png');width:800px;height:400px;} </style> <script type="text/javascript" charset="utf-8" src="js/jquery.min.js"></script> <script type="text/javascript"> var isdrag=false; var tx,x; $(function(){ document.getElementById("moveid").addEventListener('touchend',function(){ sdrag = false; }); document.getElementById("moveid").addEventListener('touchstart',selectmouse); document.getElementById("moveid").addEventListener('touchmove',movemouse); }); function movemouse(e){ if (isdrag){ var n = tx + e.touches[0].pageX - x; $("#moveid").css("left",n); return false; } } function selectmouse(e){ isdrag = true; tx = parseInt(document.getElementById("moveid").style.left+0); x = e.touches[0].pageX; return false; } </script> </head> <body> <div align="left" class="window"> <div id="moveid" class="dragme"> 這是一個能夠經過觸摸屏拖動的demo<br> 這個demo花費了我半天時間,緣由是之前歷來沒有作過面向觸摸屏的Web,按說mousedown,mouseup,mousemove和touchstart,touchend,touchmove 之間是能夠互通的,也就是說通常面向pc開發的mouse時間對touch事件有效,聽說是效率有差別。可是pc上測試沒有任何問題,在手機上就是無效。 而後…… 而後百度了好久好久…… </div> </div> </html>