我有这个小块的代码,我想模拟从一个点到另一个div的拖动..我用jquery.simulate.js脚本,但我得到错误在控制台说.. “$ .ui.mouse._mouseDown是不是一个函数”在jquery中模拟鼠标拖动
<html>
<head>
<style>
.box {
background-color:#b0c4de;
}
</style>
<script type="text/javascript" src="jquery-1.7.1.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.17.custom.min.js"></script>
<script type="text/javascript" src="jquery.simulate.js"></script>
<script>
$(document).ready(function() {
var myDiv = $("#myDiv");
myDiv.draggable();
// This will set enough properties to simulate valid mouse options.
$.ui.mouse.options = $.ui.mouse.defaults;
var divOffset = myDiv.offset();
// This will simulate clicking down on the div - works mostly.
$.ui.mouse._mouseDown({
target: myDiv,
pageX: divOffset.left,
pageY: divOffset.top,
which: 1,
preventDefault: function() { }
});
});
</script>
</head>
<body>
<div id="myDiv">hello</div>
</body>
</html>
伟大的插件,真的很有用!感谢:-) – lorcan 2013-05-31 09:49:25
而你如何拖动到指定的元素?不是x/y – Nakilon 2015-11-24 17:42:39
@Nakilon查看[插件的文档](https://github.com/j-ulrich/jquery-simulate-ext/blob/master/doc/drag-n-drop.md): '('#myDiv')。simulate(“drag-n-drop”,{dragTarget:otherDiv});' – Ignitor 2015-11-25 10:55:56