I need to be able to move a div with my mouse and store the new pos of the div in database to remember the display. How can I do it?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would highly recommend you look into jQuery UI and the draggable interaction. Basically, you’ll want to add the code to your draggable div (assuming it has id=’draggable’):
And, then put your necessary behavior in the stop event. More specifically, you’d do this:
As for the database storing, you could use an AJAX call in the above function, or you could store it in-page, such that some form-send or other action results in the positional information being passed to the server and stored inline with other data. I’d be careful with an AJAX call, since you may bomb your db with position data with every dragging on every browser. Depends on your app…