开发者

Set position of draggable div

开发者 https://www.devze.com 2023-04-11 04:15 出处:网络
I\'m doing a little application using jQuery and JQuery ui. I\'ve defined a dragable div, and it works perfectly, but I want to set the position of the div when a click a button...

I'm doing a little application using jQuery and JQuery ui.

I've defined a dragable div, and it works perfectly, but I want to set the position of the div when a click a button...

I read here in stackOverflow to do this:

element.position().top = topUserDefined;
element.position().left = leftUserDefined;

I did an alert of element.pos开发者_StackOverflow社区ition().top before and after this assignment and the new value it's not assigned, it keeps the original one...

Any Idea??? Thanks!


.position() gets the position. It doesn't set the position. It actually uses element.offsetLeft and element.offsetTop (compared to element.offsetParent position) those are read only.

Change inline CSS value to move your element:

element.css({'top': 10, 'left' : 20})
0

精彩评论

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

关注公众号