Mike Turner
Mike Turner

Reputation: 1

How to add cookies to a drag and drop div

Hello i have added a drop and drop feature to my site See Here and as i am a beginner i don't know anything about adding cookies to a page or a div, i would like to have a save button which will save the position of the div so that when a user returns to a page it will be where they left it, any help will be appreciated,

Upvotes: 0

Views: 422

Answers (1)

Henrik N
Henrik N

Reputation: 16294

Seems you're using jQuery.

Include jquery.cookie.js. You can now set cookies like $.cookie('position_x', 123) and get them like $.cookie('position_x').

The drag-and-drop library should have some callback that is run when you stop dragging. In that callback, save the x and y position away in separate cookies (to keep things simple).

When the page loads, check for those cookies and use the values to position the element.

Upvotes: 1

Related Questions