好的,所以我一直致力于使用本地存储来保存调整大小的元素
当您加载页面时,ui 代码会添加到调整大小的 div 中。 起初您可以调整元素的大小,但如果您保存它并刷新页面,则会再次添加调整大小的 ui 代码,这会破坏它。我知道我可以在保存之前运行替换,但我想知道是否还有其他更有效的方法。
代码添加了不止一次。
http://jsfiddle.net/code_cookies/Spkzq/95/
<div class="ui-resizable-handle ui-resizable-e" style="z-index: 1000;"></div>
<div class="ui-resizable-handle ui-resizable-s" style="z-index: 1000;"></div>
<div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se" style="z-index: 1000;"></div>
JS:
if (localStorage.pins === "") {
$('#draggable').html('<div id="image"class="resize" style="padding:20px; width:200px; height:200px; background-color:white;"><img class="" width="100%" height="100%" src="http://i48.tinypic.com/31368e9.jpg"/></div>');
}
else {
$('#draggable').html(localStorage.pins);
}
$("#image").resizable();
$('#save').click(function() {
localStorage.pins = $('#draggable').html();
});
最佳答案
您可以通过调用 destroy
删除 jquery UI 添加的所有内容:
$("#image").resizable( "destroy" );
关于javascript - jquery ui 添加不必要的代码和破坏东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16490140/