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

如何從一個 HTML5 畫布拖放到另一個

How to drag and drop from one HTML5 canvas to another(如何從一個 HTML5 畫布拖放到另一個)
本文介紹了如何從一個 HTML5 畫布拖放到另一個的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

我試圖弄清楚如何將圖像從一個畫布拖放到另一個畫布.假設(shè)畫布彼此相鄰,是否可以無縫地將某些東西拖過邊界?如果沒有,將 div 拖到畫布上,獲取其 ID,然后通過響應(yīng)畫布上的 mouseup 位置來放置它是不是更好?

I'm trying to figure out how to drag and drop an image from one canvas to another canvas. Assuming the canvases are next to each other, would it be possible to seamlessly drag something across the border? If not, is it a better idea to drag a div over the canvas, get its ID, and place it by responding to the mouseup location on the canvas?

推薦答案

不要在畫布上拖動項目.畫布是一種非保留模式(或即時模式) 圖形 API.您發(fā)出繪圖命令并獲得像素.模擬拖動包括跟蹤用戶的鼠標移動并選擇反復(fù)清除并使用不同參數(shù)重新繪制畫布,以使某些像素子集看起來像一個有凝聚力的對象一樣移動.

You don't drag items on a canvas. A canvas is a non-retained mode (or immediate mode) graphics API. You issue draw commands and you get pixels. Simulating dragging is comprised of tracking the user's mouse movements and choosing to repeatedly clear and re-draw the canvas with different parameters to make some subset of the pixels appear to move as a cohesive object.

將此與 HTML 或 SVG 進行對比,在其中您實際上更改了真實 DOM 對象的位置/變換屬性,并且當(dāng)您的文檔的視覺表示自動更新時,手表會自動更新.

如果你有兩個畫布并且想要從一個畫布拖動到另一個畫布,我會做的是:

If you have two canvases and want to drag something from one to the other, what I would do is:

  1. 將鼠標放在菜單"畫布上,以編程方式創(chuàng)建一個與對象一樣大的新畫布,并(使用絕對 CSS 定位)將其放置在用戶單擊的項目上方.
  2. 將項目繪制到該畫布上.
  3. 跟蹤文檔上的 mousemove 事件,并更新畫布相對于鼠標的位置.
  4. 當(dāng)用戶在目標畫布上釋放鼠標時,扔掉(或隱藏)您拖動"的小畫布,并在適當(dāng)位置使用拖動的項目重新繪制主畫布.
  1. On mouse down on the 'menu' canvas, create a new canvas programmatically just as large as the object, and (using absolute CSS positioning) place it over top of the item the user clicked on.
  2. Draw the item onto that canvas.
  3. Track the mousemove event on the document, and update the position of the canvas relative to the mouse.
  4. When the user releases the mouse over the destination canvas, throw away (or hide) your tiny 'dragging' canvas, and re-draw the main canvas with the item that was dragged in the appropriate location.

不過,我在這里可能真正要做的是使用 SVG.;)

Though, what I'd probably really do here is use SVG. ;)

這篇關(guān)于如何從一個 HTML5 畫布拖放到另一個的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How do I write FileReader test in Jasmine?(如何在 Jasmine 中編寫 FileReader 測試?)
JS/HTML5 WebSocket: Connect without HTTP call(JS/HTML5 WebSocket:無需 HTTP 調(diào)用即可連接)
CSS: Repeat Table Header after Page Break (Print View)(CSS:分頁后重復(fù)表頭(打印視圖))
Put HTML head in another file(將 HTML 頭放在另一個文件中)
What is the real difference between the quot;headquot; and quot;headerquot; tag?(“頭和“頭之間的真正區(qū)別是什么?和“標題標簽?)
Header/Footer Layout with 100% Content Height in IE8(IE8 中具有 100% 內(nèi)容高度的頁眉/頁腳布局)
主站蜘蛛池模板: 黄色一级毛片免费看 | 日本a∨视频| 日本精品视频在线 | 欧美一级毛片在线播放 | 黄色在线免费观看 | 日韩精品免费在线观看 | 99re66在线观看精品热 | 亚州无限乱码 | 欧美在线视频免费 | 国产精品久久久久婷婷二区次 | 精品综合| 最新91在线 | av网站免费| 碰碰视频 | 精品一二三区 | 欧美精品中文字幕久久二区 | 久久精品欧美一区二区三区不卡 | 欧美日韩视频在线第一区 | 亚洲精品99| 国产日韩电影 | 国产一区视频在线 | 国产成人91视频 | 国产97在线看 | 中文日韩在线视频 | 日韩中文不卡 | 精品久久久久久 | 国产免费一区二区三区 | 成人h动漫精品一区二区器材 | 久久久精品一区 | 久久久精品亚洲 | 欧美另类日韩 | 天天曰天天干 | 久久久久久国产精品 | 国产精品久久久久久久免费大片 | 天天干天天操天天射 | 久久综合一区二区 | 五月天婷婷综合 | 99久久婷婷国产综合精品电影 | 91一区二区三区在线观看 | 亚洲男女激情 | 一区二区在线不卡 |