简体   繁体   中英

Set position of draggable div

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.position().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})

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