久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

html5 拖放 FOR MOBILE

html5 drag and drop FOR MOBILE(html5 拖放 FOR MOBILE)
本文介紹了html5 拖放 FOR MOBILE的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我在 w3schools 上找到了這個用于拖放的代碼,它適用于桌面,但不適用于移動設備.

I found this code on w3schools for drag and drop, which works on a desktop, but not mobile devices.

我需要修改什么才能識別觸摸?

What do I need to modify so that it recognizes touch?

<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
#div1 {width:350px;height:70px;padding:10px;border:1px solid #aaaaaa;}
</style>
<script>
function allowDrop(ev)
{
ev.preventDefault();
}

function drag(ev)
{
ev.dataTransfer.setData("Text",ev.target.id);
}

function drop(ev)
{
ev.preventDefault();
var data=ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
}
</script>
</head>
<body>

<p>Drag the W3Schools image into the rectangle:</p>

<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<br>
<img id="drag1" src="img_logo.gif" draggable="true" ondragstart="drag(event)" width="336" height="69">

</body>
</html>

推薦答案

大多數移動設備不監聽綁定到 DOM 的拖動事件.我會推薦使用 touchmove 事件和隨之而來的事件.它看起來像:

Most mobile devices do not listen to the drag events that are bound to the DOM. I would recommend using the touchmove event and the events that go along with with it. It would look something like:

選項 1

 <!DOCTYPE HTML>
 <html>
 <head>
 <style type="text/css">
       #div1 {width:350px;height:70px;padding:10px;border:1px solid #aaaaaa;}
 </style>
 </head>
 <body>

 <p>Drag the W3Schools image into the rectangle:</p>

 <div id="div1"></div>
 <br>
 <img id="drag1" src="img_logo.gif width="336" height="69">

 <script type="text/javascript">
  var el = document.getElementById('drag'); 

  el.addEventListener("touchstart", handleStart, false);
  el.addEventListener("touchend", handleEnd, false);
  el.addEventListener("touchcancel", handleCancel, false);
  el.addEventListener("touchleave", handleEnd, false);
  el.addEventListener("touchmove", handleMove, false);

  function handleStart(event) {
      // Handle the start of the touch
  }

  // ^ Do the same for the rest of the events

</script>
</body>
</html>

handleStart、handleEnd 等是從事件觸發的回調,您可以在其中處理觸摸事件.

The handleStart, handleEnd, etc. are your callbacks that are fired from the event, which is where you can handle touch event.

如果您不想完成觸摸事件方面的所有繁重工作,那么我建議您使用 JQuery Touch Punch 之類的庫.我用過它,它在 iOS 上運行良好.

If you don't want to do all of the heavy lifting as far as the touch events, then I would recommend a library such as JQuery Touch Punch. I've used it and it works very well on iOS.

這里是庫的鏈接,您還可以在自己的移動設備上測試它的性能:http://touchpunch.furf.com/

Here's a link to the library where you can also test out its performance in your own mobile device: http://touchpunch.furf.com/

選項 2(更好的選項)像這樣包含 JQuery Touch 打孔器:

OPTION 2 (BETTER OPTION) JQuery Touch punch is included like so:

在您的頁面上包含 jQuery 和 jQuery UI.

Include jQuery and jQuery UI on your page.

<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://code.jquery.com/ui/1.8.21/jquery-ui.min.js"></script>

// Download this from the link above
<script src="jquery.ui.touch-punch.min.js"></script>

<script>
    $('#drag1').draggable();
    $( "#div1" ).droppable({
        drop: function( event, ui ) {
          $( this )
            .addClass( "isDropped" )
            .html( "Dropped!" );
        }
      });
    });

</script>

這篇關于html5 拖放 FOR MOBILE的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 認為文檔“準備好之前,如何讓我的 jasmine 測試裝置加載?) - IT屋-程序員軟件開發技術
What do jasmine runs and waitsFor actually do?(jasmine 運行和等待實際上是做什么的?)
How to provide mock files to change event of lt;input type=#39;file#39;gt; for unit testing(如何提供模擬文件來更改 lt;input type=filegt; 的事件用于單元測試)
How to unit test a chained method using Jasmine(如何使用 Jasmine 對鏈式方法進行單元測試)
How do I inject $rootScope into an AngularJS unit test?(如何將 $rootScope 注入 AngularJS 單元測試?)
Jasmine - How to spy on a function call within a function?(Jasmine - 如何監視函數中的函數調用?)
主站蜘蛛池模板: 欧美视频第三页 | 欧美激情久久久 | 一级爱爱片 | 亚洲成人免费视频在线观看 | 久久一区二区三区免费 | 国产精品1 | 午夜免费成人 | 不卡一二三区 | 国产在线一区二区 | 一级毛片免费看 | 精品一区二区久久久久久久网精 | 产真a观专区| 国产精品一级 | 4h影视| 天天色av | 超碰免费在线观看 | 国产欧美精品一区二区 | 性色综合| www.9191| 亚洲精品电影在线 | 亚洲精品久久久久久首妖 | 国产资源一区二区三区 | 精品日韩欧美一区二区 | 色资源在线 | 国产精品国产成人国产三级 | 国产一级片av| 99国产视频| 亚洲视频在线看 | 欧美福利| www.久久 | 精品久久久久久国产 | 久热国产在线 | 免费视频一区二区 | 少妇淫片aaaaa毛片叫床爽 | 欧美在线一级 | 国产成人精品免费视频大全最热 | 91精品国产综合久久久久久蜜臀 | 亚洲精品日韩视频 | 欧美激情精品久久久久久 | 国产精品成人一区二区三区夜夜夜 | 一区二区三区回区在观看免费视频 |