Question

I browsed through topics about saving element position in localStorage when this element is draggable with Jquery UI. But I didn't find solution.

In my HTML, there is <div id="canvas"></div> that we can drag inside page.

and in my script, there is :

$('#canvas').draggable({
 containment: 'parent'
});

I tried with localStorage.setItem('canvas', 'top', 'left'); for saving top and left proprieties but it seems wrong. Do I ask too much to localStorage or is it possible to make it with?

I'm new with JS and Jquery, I'm sorry by advance if my problem looks easier.

thank you,

PS: Here is http://jsfiddle.net/remibenault/yUw63/30/ with draggable div and slider.

Was it helpful?

Solution

You are not using the LocalStorage API correctly. The right way to use setItem is localStorage.setItem(key, value). You passed 3 args. You probably want to set 2 keys:

localStorage.setItem('canvasTop', valuehere);
localStorage.setItem('canvasLeft', anotherValuehere);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top