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!
Draggable Div is a kind of element that you can drag anywhere.
To make an object draggable set draggable=true on that element. Just about anything can be drag-enabled: images, files, links, files, or any markup on your page.
The draggable (option) method specifies that an HTML element can be moved in the HTML page. Here, the option parameter specifies the behavior of the elements involved. Syntax: $(selector, context).
All you need to do is define draggable=true in your element and code the relevant ondragstart and ondragend logic. This works with both vanilla JS and frameworks like React.
.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})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With