简体   繁体   English

无法正确触发jQuery拖动事件

[英]Cant trigger a jquery drag event properly

I'm trying to trigger the drag event of a div named ts1 when user drags the mouse anywhere in the body. 当用户将鼠标拖动到身体中的任何位置时,我试图触发名为ts1的div的拖动事件。

the div ts1 has a drag function on it (jquery tagsphere). div ts1上具有拖动功能(jquery tagsphere)。 What i'm trying actually to achieve is to trigger $('#ts1').tagsphere() or something 我实际上试图实现的是触发$('#ts1')。tagsphere()之类的东西

after about 3-4 hours testing and looking for answers, this is my best result: 经过大约3-4个小时的测试并寻找答案之后,这是我最好的结果:

$('body').bind("drag dragstart dragend",function(event){
            $("#ts1").trigger(event);
            return false;
        });

BUT this still doesn't trigger it.... 但是这仍然不会触发它。

why? 为什么? what am i doing wrong? 我究竟做错了什么? is there a solution out there already that works? 有没有可行的解决方案? cant seem to find 1 似乎找不到1

EDIT 编辑

Sorry guys...seems to be too complicated for me..abandoning post. 对不起...对我来说似乎太复杂了。

It seems the dragging function isn't bound to 'ts1' but rather a different element created by the tagsphere function, thus making my question irrelevent. 似乎拖动功能未绑定到“ ts1”,而是由tagsphere功能创建的其他元素,因此使我的问题变得无关紧要。

use triggerHandler instead of trigger : 使用triggerHandler代替trigger

$('body').bind("drag dragstart dragend",function(event){
                    $("#ts1").triggerHandler('drag');
                    return false;
                });

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

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