简体   繁体   English

如何在JQuery中成功遍历一组类?

[英]How can I successfully loop through an array of classes in JQuery?

I'm trying to pass an array of classes holding a comment each into a function that will display all the comments in a list. 我正在尝试将一个包含注释的类数组传递给一个函数,该函数将显示列表中的所有注释。 The purpose of the function is to make the list drop down down with an animated feel to it. 该功能的目的是使列表下拉,并带有动画效果。 Slightly different to use .slideDown and very similar to google+'s way of showing all comments of a post. 使用.slideDown略有不同,与谷歌+显示帖子的所有评论的方式非常相似。

Here is a JSFiddle link from one of my other questions. 这是我的其他一个问题的JSFiddle链接。 This what I'm trying to do: 这就是我想要做的:

http://jsfiddle.net/MZzUr/9/ http://jsfiddle.net/MZzUr/9/

Here is my attempt to do the same thing but using an array of classes holding the comments instead of a for loop: 这是我尝试做同样的事情,但使用一个包含注释而不是for循环的类数组:

http://jsfiddle.net/A9WLc/4/ http://jsfiddle.net/A9WLc/4/

Don't intend to give up on this.. been at it for days now. 不打算放弃这个......现在已经好几天了。 Thanks in advance. 提前致谢。 Kind regards 亲切的问候

When you use items[0] it returns the DOM node, not a jQuery object. 当您使用items[0]它返回DOM节点,而不是jQuery对象。 It is equivalent of using .get(index) . 它相当于使用.get(index) You want to use .eq(index) which returns the jQuery object. 您想使用返回jQuery对象的.eq(index)

var myItem = items.eq(0);
var height = myItem.height();
myItem.hide();

I think I know what you are going for. 我想我知道你的意思。 This isn't exactly it but it might be useful: http://jsfiddle.net/xkfqN/19/ 这不完全是它但可能有用: http//jsfiddle.net/xkfqN/19/

I have tried to recreate how google does their animation for a social network I worked on but gave up and just went with the way facebook does it...it just pops :) I don't know what kind of voodoo magic google does but it is really hard to replicate. 我试图重新创建谷歌如何为我工作的社交网络制作动画,但放弃了,只是按照Facebook的方式去做...它只是流行:)我不知道什么样的伏都教魔法谷歌但是它真的很难复制。

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

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