开发者

jQuery: position() on created element

开发者 https://www.devze.com 2023-01-03 16:36 出处:网络
The following code creates a div at the bottom of the page: var popup = $(\'<div id=\"popup\" />\')

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

精彩评论

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