如何在拖动时关闭元素 CSS 背景
我使用 JavaScript 构建了一个拖放界面,用户可以单击并拖动链接(有时具有 CSS 背景图像)并将其拖放到画布上。
我的问题是,拖动过程中鼠标光标下方有链接背景图像。我需要添加自己的光标设计,那么有什么方法可以关闭此 CSS 背景,使其在拖动时不跟随鼠标?
I've build a drag and drop interface using JavaScript where users can click and drag a link (that sometimes has a CSS background image) and drop it onto the canvas.
My problem is that the mouse cursor has the link background image beneath it during dragging. I need to add my own cursor design, so is there any way to turn this CSS background off so that it doesn't follow the mouse upon dragging?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过为锚标记设置 :active 伪类?
http://www.w3schools.com/cssref/sel_active.asp
那么如果是还没有用,你可以在减速后使用 !important 吗?
例如,
当用户释放背景图像时应该返回。
have you tried setting :active pseudo class for anchor tags?
http://www.w3schools.com/cssref/sel_active.asp
then if that isn't work quite yet you could use !important after your deceleration possibly?
and example could be
when the user releases the background image should return.
我发现这个问题的最佳解决方案是使用 jQuery 将 e.preventDefault() 分配给链接的单击事件,从而禁用背景拖动效果。然后,如果您希望在拖动时使用自定义光标,请编写一个脚本以将绝对定位的 div(以图像作为背景)的 x,y 线与鼠标位置相匹配。
The best solution I found for this problem was to use jQuery to assign e.preventDefault() to the click event of the link, thus disabling the background drag effect. Then, if you want a custom cursor upon dragging, write a script to match an absolutely positioned div's (with the image as the background) x,y cords to the mouse position.