我怎样才能做到不存在“幽灵”?当我在 Firefox 中拖动图像时?
当您拖动图像时,当您按住鼠标时,会有一个半透明的重影图像跟随您的鼠标。
有没有办法应用 CSS/JS 来消除特定部分的这种效果?
When you drag an image , there is a semi-transparent ghost image that follow your mouse when you hold it down.
Is there some way to apply CSS/JS to remoe this effect on a certain portion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
最简单的方法是为
setDragImage
设置非常大的x
和y
坐标,使其远离屏幕。例如:传递给
setDragImage
的实际元素并不重要。为了方便起见,我们在这里使用相同的元素。The easiest way is to set very large
x
andy
coordinates tosetDragImage
to its away from the screen. For example:The actual element you pass to
setDragImage
doesn't really matter. We use the same element here for convenience.在浏览器中禁用该功能的唯一方法(在 Safari 中执行相同的操作)是从
img
上的onmousedown
事件返回false
元素(或event.preventDefault()
)并使用 javascript 处理其余的拖动操作。几乎每个主要的 JavaScript 库都支持“拖”和“放”。您可以使用他们的代码作为起点,或者如果您已经在页面上使用了库,则可以直接使用它。
The only way to disable that in the browser (It does the same thing in Safari) is by returning
false
from theonmousedown
event on theimg
element (orevent.preventDefault()
) and by handling the rest of the drag operation with javascript.Pretty much every major JavaScript library has support for 'dragging' and 'dropping'. You could use their code as a starting place or just use it outright if you already are using a library on your page.
只需向图像添加属性
draggable="false"
即可。另外,添加一个容器div
。例如
,另外,添加
Just add attribute
draggable="false"
to the image. Also, add a containerdiv
.E.g.
Also, add
您可以尝试使用 css 背景图像而不是带有 img 标签的实际图像。
You could try using css background images instead of actual images with the img tag.
您需要从
ondragstart
事件返回 false。我自己也遇到过这个问题,我就是这样解决的。这也是 IE7 中的一个问题。问题在于IE的拖放api,它的标准化为html5,以及firefox对其的后续实现。其他使用 javascript 库进行拖放的建议将不起作用。 (我已经在使用 jquery UI),因为这是 Firefox 中最近出现的事情,而 jQuery UI 似乎并没有考虑到这一点。
You need to return false from the
ondragstart
event. I had this issue myself, and that's how I've solved it. It's an issue in IE7 as well. The problem is IE's drag and drop api, its standardisation into html5, and firefox's subsequent implementation of it.Others suggestions of using a javascript library for drag and drop won't work. (I was already using jquery UI), as this is a recent thing in firefox, and jQuery UI doesn't seem to account for it.
恐怕这是浏览器的行为/功能。我不确定是否有任何特定的 FF CSS 样式可以处理这个问题。
您可能想要修改 Firefox 的代码以拥有您自己的 Firefox。如果您正在寻找一些非编程方式执行此操作的方法,我想您必须在 superuser.com 上发帖:P
I'm afraid it's the browser behaviour/feature. I'm not sure of any specific FF CSS style which can handle that.
You might want to modify the Firefox's code to have your own firefox. If you are looking for some means to do it non-programmatically, I guess you have to post in superuser.com :P
about:config
中有一个 Firefox 选项可以关闭此功能 -nglayout.enable_drag_images
- 但显然这只对你有用。我猜您想为所有访问者删除它?如果您想进行拖放操作,放弃,也许尝试 jQuery UI 或其他 JS 库?您应该能够非常轻松地移动其他元素,并且您可以使用蒂姆在其中一个元素上所说的背景图像。
另一个优点是您可以使用 CSS 精灵效果来减少 HTTP 请求。我用 jQuery UI 制作了一个 拼图游戏,实际上只有一张图像,但它看起来有好几个。
There is be a Firefox option in
about:config
to turn this off -nglayout.enable_drag_images
- but obviously that will only work for you. I'm guessing you want to remove it for all visitors?If you want to do drag & drop, maybe try jQuery UI or another JS library? You should be able to move other elements quite easily, and you could use a background image like Tim said on one of those.
Another advantage to that is you can use CSS sprite effects to reduce HTTP requests. I made a jigsaw puzzle with jQuery UI, which is actually only one image, but it looks like several.