javascript - how to make a 'div' element drag on iphone -


this code,for reason , can't use javascript lib ,like ;jquery:

<!doctype html public "-//wapforum//dtd xhtml mobile 1.0//en" "http://www.wapforum.org/dtd/xhtml-mobile10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" style="height: 100%;">     <head>          <meta http-equiv="content-type" content="text/html; charset=utf-8">          <meta name="viewport" content="width=device-width,minimum-scale=0.3,maximum-scale=5.0,user-scalable=yes">         <meta name="apple-mobile-web-app-capable" content="yes" />      </head> <body style="height: 100%;margin:0;">  <style type="text/css"> #draggable { width: 100px; height: 100px; padding: 0.5em; float: left; margin: 10px 10px 10px 0;      border:1px solid #dddddd;     color:#333333;     background:#f2f2f2;     cursor:move;     } #droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px;      border:1px solid #e78f08;     color:#ffffff;     font-weight:bold;     background:#f6a828;     overflow:hidden;     } #droppable.highlight{      } #draggable.end{     left:0px !important;     top:0px !important;     } </style>    <div class="demo" style="margin:0 auto;height: 100%;">     <div id="a" style="float:left;height:50%;margin:0 100px 0 0;width:100%;background:#333;">         <div id="draggable">             <p>drag me target</p>         </div>     </div>     <div id="droppable" >         <p>drop here</p>     </div> </div><!-- end demo -->  <script type="text/javascript"> var $=function(id) {      return document.getelementbyid(id);  }  $('draggable').ontouchstart = function(evt){   console.log(evt.pagex + "/" + evt.pagey); }  $('draggable').ontouchmove = function(e){   if(e.touches.length == 1){ // deal 1 finger     var touch = e.touches[0]; // information finger #1     var node = touch.target; // find node drag started     node.style.position = "absolute";     node.style.left = touch.pagex -node.offsetwidth /2+ "px";     node.style.top = touch.pagex -node.offsetheight/2+ "px";   } } </script>  </body> </html> 

my code can not generate right track,

so can .

thanks

i found one. have tested on computer , on ipad2, , works perfect on both devices... maybe fit needs:

http://furf.com/exp/touch-punch/index.html


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -