简体   繁体   English

如何手动触发jQuery drag()函数?比如$(element).trigger('drag');

[英]How to trigger jQuery drag() function manually? like $(element).trigger('drag');

I have an img element which is draggable. 我有一个可拖动的img元素。 Now I want to trigger the drag() event manually like how do we trigger 'click' event as $(element).trigger('click'). 现在我想手动触发drag()事件,就像我们如何触发'click'事件$(element).trigger('click')。 Thanks. 谢谢。

Here is the function definition that I have 这是我的函数定义

$('#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();
        }
    });

Here is jquery ui plugin 这是jquery ui插件

https://github.com/jquery/jquery-ui/blob/9e8e339648901899827a58e5bf919f7dda03b88e/tests/jquery.simulate.js https://github.com/jquery/jquery-ui/blob/9e8e339648901899827a58e5bf919f7dda03b88e/tests/jquery.simulate.js

include that on the page and then simply use 在页面上包含,然后简单地使用

$("#myElement").simulate('drag');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM