Html5 Drag and Drop Mouse Position in Firefox(Firefox 中的 Html5 拖放鼠标位置)
问题描述
我有一个使用拖放的 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 拖放鼠标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Firefox 中的 Html5 拖放鼠标位置


基础教程推荐
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- 动态更新多个选择框 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01