jQuery:如何重置页面上的所有元素位置?

时间:2010-05-15 23:44:10

标签: jquery colorbox

假设我有一堆带有“apple”类的DIV,以及另一堆带有“orange”类的DIV。

所有这些DIV都有不同的位置,但我想使用jQuery函数在页面上为它们的父容器分配新的位置而不重新加载。

因此,例如,如何在没有重新加载页面的情况下,将所有具有“apple”类的DIV设置为相对于父容器的“top”值“200px”?

谢谢!

1 个答案:

答案 0 :(得分:3)

var $apples = $('.apple'); // caching your elements

$apples.parent().css('position', 'relative'); // setting the parent to a relative position

$apples.css('position', 'absolute')  // setting an absolute position, relative to the parent
       .css('top', '200px');  // setting the top position
相关问题