如何将两个 jquery 对象一起制作动画
我想同时为两个 jquery 对象设置动画(使用 jquery slideUp
方法)
我有两个 div 已经被“缓存”到一个变量中,如下所示:
var div1 = $('body').find('#someId');
var div2 = $('body').find('#someOtherId');
我已经缓存了这些,因为它们采用由于页面布局(使用框架集和框架......不要问),需要进行大量的处理。
不管怎样,
如果我像下面那样做幻灯片动画,它们并不是完美同步的(它们排列在一起,所以你可以很容易地在视觉上看到它)
div1.slideUp(500);
div2.slideUp(500);
所以我尝试像这样包装它,
$(div1, div2).slideUp(500);
但只有 div1 幻灯片。
无论如何,有没有办法让它工作,同时仍然维护缓存的对象?
编辑:给div一个类名不会触发动画。我认为这可能与我使用框架集有关。 jquery 代码位于顶部框架中,因此它不会查看该类的其他框架。这就是我缓存对象的原因
I want to animate two jquery OBJECTS at the same time (using the jquery slideUp
method)
I have two divs that have already been 'cached' into a variable like so:
var div1 = $('body').find('#someId');
var div2 = $('body').find('#someOtherId');
I have cached these because they take a considerable amount of processing to find due to the page layout (using framesets and frames...don't ask).
Anyway,
If I do the slide animation like below, they are not in perfect sync (they are lined up so you can easily see it visually)
div1.slideUp(500);
div2.slideUp(500);
So I tried wrapping it like so,
$(div1, div2).slideUp(500);
but only div1 slides.
Is there anyway to get this to work while still maintaining the cached objects?
Edit: Giving the div's a class name does not trigger the animation. I think it may have something to do with the fact that I'm using framesets. The jquery code is in the top frame and so it will not look into other frames for the class. That is why I cached the objects
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你可以像这样做你想做的事:
我做了一个快速的 jsfiddle 你可以在这里查看。
You can do what you want like this:
I made a quick jsfiddle you can check out here.
最短的做法是使用共享类,然后选择具有该类的所有项目:
否则,您可以使用
.add()
方法 http://api.jquery.com/add/在这种情况下,你的代码将变成这样:
The shortest thing to do is to use a shared class and then select all the items with that class:
Otherwise, you could use the
.add()
method http://api.jquery.com/add/In this case your code will become something like this:
为什么你不向 to div 添加一个类并添加像这样的选择器
添加动画的选择器就像这样
并且避免找到一些变量并创建更多选择器
why you dont add a class to the to div and add do the selector like this
the selector that add the animation it's like this
and that avoid to find some variables and make more selectors
为两个 div 指定相同的类,即
slide
,然后将代码更改为$('.slide').slideUp(500)
。Give the two divs the same class, i.e.
slide
and then change your code to$('.slide').slideUp(500)
.