开发者

Absolute Positioning in JQuery after loading page and positioning elements

I want to position an element in normal css relative to the element before it, and then once it's been initially positioned makes its position independant of the one bef开发者_JAVA技巧ore it.

For example, when you click on a 'widget' in the sidebar, it collapses, and all of the 'widgets' below it move up. I don't want them to move. Thanks.


You cannot do this with pure CSS, but you can do it with jQuery, like this:

var elem = $('something');
var pos = elem.position();
elem.css({ position: 'absolute', top: pos.top, left: pos.left });

Until the Javascript runs, the element must not have position: absolute.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜