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.

有帮助吗?

解决方案

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top