简体   繁体   中英

How can I use JQuery UI to animate to a new “position”

I'm using the JQuery .postion() function to place my object relative to another. I'd like it to -animate- to that position, however.

I know how to animate, but that requires knowing the position, and in this case, I'm using .postion() to actually calculate that position:

                $(this).position(
                {
                    my: 'left top',
                    at: 'left+' + xPos + ' top+' + yPos,
                    of: $("#dropdiv1")
                });

So, is there a way to get that position as an intermediate result and then use animate() to go to that location perhaps?

If I knew the position, I'd use animate(), but the postion() call calculates that for me, so I'm not sure how to go about it.

I can't say I'm 100% certain on how it works, but after tinkering, this works perfectly:

                $(this).position(
                {
                    my: 'left top',
                    at: 'left+' + xPos + ' top+' + yPos,
                    of: $("#dropdiv1"),
                    using: function (css, calc)
                    {
                        $(this).animate(css, 200, "linear");
                    }
                });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM