2010-12-22 74 views
5

我看到使用Chrome的jQuery UI可拖动元素的奇怪行为。在下面的代码中,我创建了两个彩色块,您可以在浏览器窗口中拖动。试试吧here。一切工作正常使用IE8和FF3,但Chrome的两个坏的事情发生了:请解释这种奇怪的行为(在Chrome中)

  • 当您单击块上,该 光标变成一个I型。请注意, 在这个页面上没有内容!
  • 将其中一个块放在 之上(绿色的位于顶部)。现在 点击块并拖动它。光标变为no symbol, ,但仍可以拖动。现在放手。 尽管鼠标按钮现在变为,但它仍然被拖动,即使是 也不会被丢弃。

这看起来像的方式太简单了一个例子来打破铬或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> 

回答

7

显然是在jQuery UI 1.8.6中修复的jQuery UI中的一个错误。您正在使用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; }; 
});
+1

虽然链接仅针对未成年人的文字光标的问题,更新到jQuery UI 1.8.6修复了这两个问题。谢谢! – 2010-12-22 21:29:34

相关问题