jquery - 请解释 jQuery 拖动的这种奇怪行为(在 Chrome 中)

标签 jquery jquery-ui google-chrome drag-and-drop

我发现使用 Chrome 的 jQuery UI 可拖动元素有奇怪的行为。在下面的代码中,我创建了两个彩色 block ,您可以在浏览器窗口中拖动它们。试试吧here 。使用 IE8 和 FF3 一切正常,但使用 Chrome 会发生两件坏事:

  • 当您单击任一 block 时, 光标变成工字梁。注意那里 此页没有文字!
  • 将一个方 block 放在 其他(绿色的在上面)。现在 单击该 block 并拖动它。这 光标变成no symbol , 但您仍然可以拖动。现在放手吧。 方 block 没有被丢弃, 甚至还被拖来拖去 尽管鼠标按钮现在已抬起

这看起来方式太简单了,无法破坏 Chrome 或 jQuery。
我错过了什么吗?

<html>
<head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>

    <script>
        $(function() {
            $('<div>').addClass(  'redsquare').appendTo('body').draggable({ grid: [24, 24] })
            $('<div>').addClass('greensquare').appendTo('body').draggable({ grid: [24, 24] })
        });
    </script>

    <style>
        body {
            margin: 0 0 0 0;
        }

        .redsquare {
            position: absolute;  
            top: 48; left: 48;          
            width: 24px;
            height: 24px;
            background-color: Red;
        }            

        .greensquare {
            position: absolute;  
            top: 48; left: 96;          
            width: 24px;
            height: 24px;
            background-color: Green;
        }            
    </style>

</head>
<body>
</body>
</html>

最佳答案

显然是 jQuery UI 中的一个错误,已在 jQuery UI 1.8.6 中修复。您正在使用 1.7.2。

它并没有停止选择..

引用帖子:
http://forum.jquery.com/topic/chrome-text-select-cursor-on-drag
http://bugs.jqueryui.com/ticket/4163

一种解决方案:

$(".ui-draggable").each(function() {
  this.onselectstart = function() { return false; };
});

关于jquery - 请解释 jQuery 拖动的这种奇怪行为(在 Chrome 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4513678/

相关文章:

jQuery UI Datepicker - 前端动态日期格式但后端静态日期格式?

css - Chrome 中奇怪的边框宽度行为 - 浮点边框宽度?

google-chrome - Chrome 扩展弹出窗口闪烁问题

javascript - 将 jqWidgets 组合框限制为值列表

javascript - asp.net 网页 Web 服务仅在本地计算机上运行

javascript - 有一个按钮打开正确的表单 JQuery

jquery - Bootstrap - 将远程 Google Chart 加载到 Modal 中

jquery - 使用 Sortable 时悬停不会消失

javascript - 按钮可拖动,同时内容可编辑

google-chrome - Chrome Vimeo Iframe 自动播放不再起作用