开发者

jQuery UI Position - Selector for parent element?

开发者 https://www.devze.com 2023-03-20 13:56 出处:网络
I want to use jQuery UI\'s position utility to center a number of elements with the same class inside of their respective parent elements. Here\'s what I came up with:

I want to use jQuery UI's position utility to center a number of elements with the same class inside of their respective parent elements. Here's what I came up with:

$(".elementclass").position({
    "my": "center center",
    "at": "center center",
    "of": $(this).paren开发者_StackOverflow中文版t()
});

Unfortunately, this does not work, since the jQuery object $(this) somehow does not refer to the positioned element in this context. How can I pull this off?


How about this:

$(".elementclass").each(function(i)
{
   $(this).position({
    "my": "center center",
    "at": "center center",
    "of": $(this).parent()
   });
});


You could put it inside an "each" function like this:

$(".elementclass").each(function() {
    $(this).position({
        "my": "center center",
        "at": "center center",
        "of": $(this).parent()
    });
});

This would loop through each element with the class of "elementclass", and position each item individually. Because you're referencing each element inside the function, $(this) will refer to the element you're trying to position.

0

精彩评论

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