如何在 mootools 中链接数组?
假设您在 mootools 中有一个数组:
// get the elements and set them as slide
var slideElements = $$('.mySlideElements');
slideElements.set('slide');
// and fire the event -> would slide all elements out at the same time
slideElements.slide('out');
我如何将其放入一个链中以一次滑动一个数组?
到目前为止,只有当我知道要执行的操作的确切数量时,我才能成功链接。感谢您的帮助。
Say you have an array in mootools:
// get the elements and set them as slide
var slideElements = $('.mySlideElements');
slideElements.set('slide');
// and fire the event -> would slide all elements out at the same time
slideElements.slide('out');
How could I put this into a chain to slide them one at a time?
So far I've only succeeded in chaining if I know the exact number of actions I will be performing. Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我最终在这个方面投入了大量的工作,链接比我乍一看要棘手得多。我以前从未以这种方式使用过它:D
您绝对可以循环遍历
slideElements
数组。将元素事件相互链接是棘手的部分。我最终得到了一个循环闭合函数,该函数循环遍历每个slideElement
并将列表中的前一项链接到当前项:调用
get('slide')
返回 Fx在每个元素上设置的 .Slide 对象,然后您可以将其链接到一个函数。我的 Mootools-fu 不够强大,无法弄清楚如何将其直接链接到下一个元素的slide
属性(它应该是一个函数,但它没有' t 似乎有效),所以我最终得到了您在 chain() 调用中看到的匿名函数,这几乎同样好。循环闭包function(c1,c2)
对于防止本地i
循环变量在调用链式匿名函数时超出范围是必要的。它被设置为当第一个元素的
slide
函数被触发时的连锁反应。如果您需要在单击任何任何元素时都进行级联,您可能需要设置每个元素的onClick
事件来触发第一个元素的slide()
而不是他们自己的。无论如何,上面的代码是一个工作示例。我希望结果是您想要的。
I ended up putting a lot of work into this one, chaining was a lot trickier than I thought at first glance. I've never used it in quite this manner before :D
You can definitely loop through the
slideElements
array. Chaining the element events to each other is the tricky part. I ended up with a loop closure function that loops through eachslideElement
and chains the previous item in the list to the current item:Calling
get('slide')
returns the Fx.Slide object that was set on each element, which you can then chain to a function. My Mootools-fu wasn't strong enough to figure out how to chain it directly to theslide
property of the next element (which should be a function, but it didn't seem to work), so I ended up with the anonymous function you see inside thechain()
call, which is almost as good. The loop closurefunction(c1,c2)
was necessary to prevent the locali
loop variable from being out of scope by the time the chained anonymous function got called.It's set up as a chain reaction for when the first element's
slide
function gets triggered. If you needed the whole thing to cascade whenever any element is clicked, you'd probably want to set every element'sonClick
event to fire the first element'sslide()
and not their own.Anyway, the code above is a working example. I hope the results are what you were looking for.
在我看来,这是一种更好/“mootoolsy”的做法。 FX 实例提供了两个可以使用的东西:link: "chain" 和 onComplete: 函数。所以像这样:
这里的工作示例: http://mootools.net/shell/GmUpM/
这将适用于要滑出的无限数组长度的元素
in my opinion, this is a better / "mootoolsy" way of doing it. the FX instance provides two possible things that can be used: link: "chain" and onComplete: function. so something like this:
working example here: http://mootools.net/shell/GmUpM/
this will work with an infinite array length of elements to slide out
试试这个:
它只要求
.mySlideElements
是直接同级Try this:
It just requires that
.mySlideElements
be immediate siblings