我对jQuery的$(选择器).each()有困难 [英] I'm having difficulty with jQuery's $(selector).each()

查看:112
本文介绍了我对jQuery的$(选择器).each()有困难的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例: http://jsfiddle.net/KyW6c/2/

我有一个有序的清单。每个列表项都是我的投资组合中的项目。我正在写一些jQuery,它会将一个单击的列表项移动到有序列表的左上角。我已经完成了这个,但我遇到的问题是所点击的列表项目正在转移。这个代码在小提琴中提供(注释掉)。

I have an ordered list. Each list item is a project in my portfolio. I'm writing some jQuery that will move a clicked list item up to the top left of the ordered list. I've accomplished this, but the problem I'm encountering is that the list items below the clicked one are shifting. This code is provided in the fiddle (commented out).

我试图实现的解决方案将每个列表项的位置设置为绝对位置,并将其左右都设置为当前位置加载页面后,在有序列表中的位置。我不知道我是否遇到麻烦,因为我误解了.each()的作用,或者只是如何实现它。

The solution I'm attempting to implement will set each list item's position to absolute and left and right to it's current position within the ordered list once the page is loaded. I don't know if I'm having trouble because I misunderstand what .each() does, or just how to implement it.

谢谢。

编辑:问题是每个列表项的左侧和顶部值都设置为0,因此它们只是在左上角重叠。如果你取消注释jQuery,你会看到问题。

The problem is that each list item's left and top values are being set to 0, so they're all just overlapping on at the top left. If you uncomment the jQuery, you'll see the problem.

编辑2:我发现如果我没有在同一时间将位置设置为绝对设置左侧和顶部属性,它可以正常工作。

EDIT 2: I discovered that if I don't set the position to absolute at the same time that I set the left and top properties, it works properly.

推荐答案

http://jsfiddle.net/KyW6c/11/

在得到一点帮助时弄明白了一个朋友。谢谢,马特

Got it figured out with a little help from a friend. Thanks, Matt!

这篇关于我对jQuery的$(选择器).each()有困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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