delete
delete

Reputation:

How can I change the position of a div using jQuery?

I'd like reposition a div on my website using jQuery.

Basically I have a toolbar with many slots. I'm using the Draggable+Droppable items from jQueryUI to handle the moving and dropping.

I'd like the dropped element to be positioned dead in the center of the container(droppable) to simulate a 'snap-to-center' effect.

How would I do this? I'm pretty new to jQuery, sorry for the simple question.

Thanks!

Upvotes: 1

Views: 800

Answers (1)

jamesmortensen
jamesmortensen

Reputation: 34048

This actually sounds more like a CSS problem. I would suggest that you create a CSS rule that will center the divs in the container using a class attribute. Then when you drag and drop the DIV element you can simultaneously apply the CSS class to ensure the div is centered.

Upvotes: 4

Related Questions