2010-12-22 75 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

相關問題