您将如何使用Trigger触发jquery可拖动的开始,拖动,停止事件? [英] How would you use Trigger to fire the jquery draggable start, drag, stop events?

查看:144
本文介绍了您将如何使用Trigger触发jquery可拖动的开始,拖动,停止事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个可拖动的对象并且具有启动,拖动,停止功能,我将如何触发它们?

If i have an object that is draggable and has Start, Drag, Stop functions, how would i trigger them?

我认为会引起问题的问题是传递给函数的参数.

the issue that i am thinking would cause issues is the arguments passed into the function.

我不确定是否有一种简单的方法来执行此操作,是否可以使用某种模拟,或者我是否应该创建自定义对象以将其传递给 e ui 函数属性.

I wasn't sure if there was an easy way to do this, if there was some sort of simulation that can be used, or if i should create a custom object in which would be passed into the e and ui function attributes.

我会写代码,但这很简单:

I would write code, but it is as simple as:

代码:

var $a = $("<div />").append("Test Text").appendTo("body").draggable({
    start: function(e,ui){/*...*/},
    drag: function (e,ui){/*...*/},
    stop: function (e,ui){/*...*/}
});

我想调用函数,最初我在想:

I wanted to call the functions, and originally i was thinking:

$a.draggable("option", "start")();
$a.draggable("option", "drag")();
$a.draggable("option", "stop")();

我只是进行了快速的代码遍历,以查看在哪里使用了哪些参数.

I just did a quick code walk, to see which arguments were being used where.

start:   ui.position.top|left
drag:    ui.position.top|left
stop:    ui.position.top|left, eventArgs.ClientX, eventArgs.ClientY, eventArgs.target

所有这些都具有作用域之类的东西,但是,由于它正确地连接到调用单击的对象上,因此与不引用当前对象的情况下调用该函数会有所不同.

All of these have things like scope, and this, but since it is properly attached to something calling a click would be different then just calling the function without a reference to the object at hand.

在查看了函数之后,我 SHOULD 能够创建对象以传递到触发器OR函数中,就像我在上面的语句中将其触发一样.

After looking at the functions, I SHOULD be able to just create objects to pass into the trigger OR function as i have fired it in the above statement.

推荐答案

因此,最初的想法是Trigger.它将调用与名为Listener的事件关联的事件.

So at first, the idea was Trigger. It will call the events associated with the Listener called.

我被告知的第二个选项是适用的.但是在执行内联js时,需要有一个范围....,因为在arb中调用它时范围是错误的.代码行.这不会引用正在移动的文本框,而是执行它的功能容器.

The second option i was told was apply. When doing an inline js apply though, there needs to be a scope.... because the scope is wrong when calling it in an arb. line of code. This wouldnt refer to the textbox being moved but the function container executing it.

我首先建立了一个使用过的参数列表,如您在上面看到的,并在给定了可拖动对象的范围的情况下对其进行了应用.

I first build a list of args used, as you saw above and just applied that given the scope of the draggable object.

var s = [null,{position:{top:0,left:0}}],
    d = [null,{}position:{top:0,left:0}],
    sto = [{ClientX:0, ClientY:0, target:""},{]]
$("#my_item").draggable("option", "start").apply($("#my_item"), s);
$("#my_item").draggable("option", "drag").apply($("#my_item"), d);
$("#my_item").draggable("option", "stop").apply($("#my_item"), sto);

此答案确实有效,因为它传递了正确的范围和所需的所有数据.我不确定是否有任何我不知道的隐藏功能,等等.

This answer does work, as it passes in the correct scope and all the data needed. I wasnt sure if there were any needed hidden functions, etc that i was unaware of.

这篇关于您将如何使用Trigger触发jquery可拖动的开始,拖动,停止事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆