2010-05-15 103 views
2

比方說,我有一堆DIV與一類「蘋果」,另一類DIV與一類「橙」。jQuery:如何重置頁面上的所有元素位置?

所有這些DIV都有不同的位置,但我想用一個jQuery函數爲它們分配相對於其父容器的新位置,而不需要重新加載。

例如,如何在不重新加載頁面的情況下將所有具有「apple」類的DIV設置爲相對於父容器的「200px」「top」值?

謝謝!

回答

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 
相關問題