关于 Chrome 和 IE 中 .draggable 的两个问题
我正在创建一个游戏板,其中包含可以移动的棋子,所有棋子都使用 .draggable jQuery UI 类。有一些可拖动的游戏块,它们位于网格的桌子顶部。表格和片段都是 div 元素的父级,该元素本身是可拖动的。目标是为玩家提供一个可以四处走动和观看的大型游戏区域。
URL: http://shionyr.com/gamekeeper/dragger.php
该表在 Firefox 中运行良好。然而,Chrome 和 IE 中出现了两个完全不同的问题,大概是由于我的代码处理元素的方式相同的核心问题。
Chrome: 第一次拖动父 div 后,它的拖动效果很有趣。具体来说,如果您第二次开始拖动它,则在您释放鼠标按钮之前它不会开始拖动。如果您重新加载页面,该问题就会修复,并且只要您将其稍微拖动到网格区域之外,该问题就不会发生。
IE:当您尝试拖动图像时,父 div 和图像会同时拖动,图像会加速以适应 div 的移动。我尝试使用 z-index 来解决这个问题,没有爵士乐。
我尝试过使用多种设置、样式、事件标签来解决此问题,但似乎没有任何方法 100% 有效。感谢您的帮助!
I'm creating a game board with pieces you can move around, all of them using the .draggable jQuery UI class. There are the game pieces, which are draggable, and these lie on top of a table which is the grid. Both the table and the pieces are parented to a div element which is, itself draggable. The goal is to give players a large play area they can move around and look at.
URL: http://shionyr.com/gamekeeper/dragger.php
The table works fine in Firefox. However, two completely different issues arise in Chrome and IE, presumably from the same core issue with how my code is handling the elements.
Chrome: The parent div drags funny after the first time you drag it. Specifically, if you start to drag it a second time, it won't start dragging until you release the mouse button. The problem fixes if you reload the page, and doesn't happen as long as you drag slightly outside of the grid area.
IE: When you attempt to drag an image, the parent div and the image drag at the same time, with the image accelerating to accomodate for the movement of the div. I tried using z-index to fix this, no jazz.
I've tried using several settings, styles, event tags to fix this problem, but nothing seems to work 100%. Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Chrome 问题:
您使用了
no-select
类来防止在拖动鼠标事件时进行选择。文档的结构:您将
no-select
类放在表格上,这使您的可拖动图像不受影响。由于浏览器的随机行为,当您通过拖动网格来移动容器时,会创建一个不可见的选择。当您第二次开始拖动时,您实际上开始拖动选定的内容,这导致拖动在鼠标松开时开始。解决方案:将
no-select
类放在容器div上而不是表格网格上。注意: jQuery UI 有一个自己的未记录的实用函数,您只需调用
$('div') 即可,而不是使用
。no-select
类。禁用选择();IE 问题:
jQuery UI 1.7+ 存在一个已知问题,该问题尚未修复,影响 Internet Explorer 下的嵌套可拖动对象。请参阅此错误报告。 更新:此错误已在 jQuery UI 1.8.16 中修复。
问题基本上是在 IE 下,即使处理了拖动事件,拖动事件也会在 DOM 上冒泡。评论中建议的解决方法是手动取消内部可拖动对象(在您的情况下是可拖动图像)上的 mousedown 事件的事件冒泡:
这只是一个 hack,直到它得到修复,希望在 jQuery UI 1.9 中。
IE9 问题: 另请注意,在 IE9 下,由于某些奇怪的原因,您的可拖动对象都无法工作。
Chrome issue:
You used a class
no-select
to prevent selection on your drag mouse events. The structure of your document:You put your
no-select
class on your table, which left your draggable images unaffected. Due to random browser behaviour, when you moved your container by dragging your grid, an invisible selection was created. When you started dragging the second time, you actually started dragging the selected content, which caused the drag to start on mouseup.Solution: Put your
no-select
class on your container div instead of the table grid.Note: jQuery UI has an undocumented utility function of its own, instead of using your
no-select
class, you can just call$('div').disableSelection();
.IE issue:
There is a known issue with jQuery UI 1.7+ which still hasn't been fixed, affecting nested draggables under Internet Explorer. See this bug report. UPDATE: This bug has been fixed in jQuery UI 1.8.16.
The problem basically is that under IE, drag events bubble up on the DOM even if they're handled. A workaround suggested in the comments is to manually cancel event bubbling of the mousedown event on the inner draggables (in your case, your draggable images):
This is just a hack until it gets fixed, hopefully in jQuery UI 1.9.
IE9 problem: Please also note that under IE9 none of your draggables work for some odd reason.