問題描述
我有一個使用拖放的 HTML5 應用程序.本質上,用戶可以將圖像從抽屜"拖到畫布上以創建更大的圖像.我希望元素落在它們被釋放的地方.我可以在除 Firefox 之外的所有瀏覽器中使用此功能.
I have an HTML5 application which utilizes drag and drop. Essentially the user can drag an image from a "drawer" onto a canvas to create a larger image. I want the elements to drop in the place where they were release. I have this working in all browsers except Firefox.
在 drop
事件中,我使用下面的方法來獲取鼠標的坐標,并計算被放置的圖像在畫布中的位置.
On the drop
event, I am using the following to get the coordinates of the mouse, and calculate the position of the dropped image within the canvas.
var top = evt.originalEvent.offsetX;
var left = evt.originalEvent.offsetY;
問題是,該屬性在 FF 中不可用.有沒有其他方法可以得到這個?沒有它,我看不到如何在 FF 中拖動和移動元素.
The issue is, this property is not available in FF. Is there any other way to get this? Without it, I can't see how to possible drag and move elements within FF.
注意:我沒有使用 canvas 元素.我正在將圖像放到一個 div 中.不確定這是否重要.
Note: I am not using the canvas element. I am dropping images to a div. Not sure if that matters.
推薦答案
在firefox中試試這個..
Try this in firefox..
var X = event.layerX - $(event.target).position().left;
var Y = event.layerY - $(event.target).position().top;
這篇關于Firefox 中的 Html5 拖放鼠標位置的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!