开发者

jQuery: position() on created element

The following code creates a div at the bottom of the page:

var popup = $('<div id="popup" />')
    .appendTo('body');

The following code causes it to position correctly once there.

$('#popup')
    .position({ my: 'left top', at: 'left bottom', of: $('#someDiv') });

But this code causes it to appear in the DOM but not be positioned anywhere (it is not visible, but it is in the DOM).

var popup = $('<div id="popup" />')
    .appendTo('body')
    .position({ my: 'left top', at: 'left bottom', of: $('#someDiv')开发者_StackOverflow中文版 });

Is there a trick to being able to use jQuery position() on an item you are creating?

Cheers, Craig


try this:

var popup = $('<div id="popup" />')
    .position({ my: 'left top', at: 'left bottom', of: $('#someDiv') })
    .appendTo('body');

Grz, Kris.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜