[英]Is it possible to drag an HTML element out of another element and trigger a change with jQuery?
[英]How to trigger jQuery drag() function manually? like $(element).trigger('drag');
我有一個可拖動的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('drag');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.