我有一个可拖动的 img 元素。现在我想手动触发 drag() 事件,就像我们如何触发 'click' 事件一样 $(element).trigger('click')。谢谢。
这是我的函数定义
$('#imgToUpload').draggable({
drag: function(event, ui) {
if (ui.position.top > 0) {
ui.position.top = 0;
}
var maxtop = ui.helper.parent().height() - ui.helper.height();
if ( ui.position.top < maxtop) {
ui.position.top = maxtop;
}
if ( ui.position.left > 0) {
ui.position.left = 0;
}
var maxleft = ui.helper.parent().width() - ui.helper.width();
if ( ui.position.left < maxleft) {
ui.position.left = maxleft;
}
ImageCropping.calculateCroppedCoordinates();
}
});
最佳答案
这里是jquery ui插件
将其包含在页面上,然后简单地使用
$("#myElement").simulate('拖动');
关于javascript - 如何手动触发 jQuery drag() 函数?像 $(element).trigger ('drag' );,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35458509/