0
使用jQuery-UI,可以通過在mousedown事件上應用.draggable()方法使元素可拖動。然後在另一個鼠標按下並拖動它(並拖動)。 是否可以使元素可拖動並通過單擊鼠標(mousedown事件)立即開始拖動。jquery-ui:可立即在mousedown上拖動
會發生什麼:
1)按藍色矩形並嘗試拖動(元素不可動的);
2)unpress rect並嘗試再次拖動(元素是可移動的)。
應該發生什麼:
1)按藍色矩形並拖動它 - >元素是可移動的。
<!DOCTYPE html>
<html>
<head>
<title>draggable() on press</title>
<meta charset='UTF-8'/>
<style>#rect{ border: 1px dotted blue; width:100px; height:100px; background-color: lightblue;}</style>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js'></script>
<script>
$(document).ready(function(){
console.log('document is ready');
$('#rect').mousedown(function(ev){
console.log(ev.target.id+' pressed');
$(ev.target).draggable();
// $(this).draggable(); // Works the same.
});
});
</script>
</head>
<body>
<div id='rect'></div>
</body>
</html>