【发布时间】:2013-07-10 22:37:31
【问题描述】:
我进行了大量研究,但我需要一个更个性化的答案,我非常肯定保存可拖动的值需要一个 cookie 解决方案,不像 jQuery .slider 你可以保存这样的值
//jQuery UI Slider
jQuery( ".slider" ).slider({
animate: true,
range: "min",
value: $("input.slider-value").val(),
min: 50,
max: 700,
step: 1,
//this gets a live reading of the value and prints it on the page
slide: function( event, ui ) {
jQuery( "#slider-result" ).html( ui.value );
jQuery( ".static_preview_image" ).height( ui.value );
},
//this updates the hidden form field so we can submit the data using a form
change: function(event, ui) {
jQuery('#hidden').attr('value', ui.value);
}
});
$( ".static_preview_image" ).css({height: $("input.slider-value").val()}); //This gives my element the height of the slider, it get stored in my slider function...
根据我的研究,.draggable 不能以同样的方式工作,它需要 cookie?
如果那是真的,有人可以解释如何以最干净的方式使用 cookie,我只想保存顶部、右侧、左侧、底部的值...
这是我的可拖动函数
$( ".MYELEMNT" ).draggable({
containment: '#_moon_static_bg_status', // I set some containment
// Read this in another post, this outputs a live value of .MYELEMNT from the start of the drag.
start: function(event, ui) {
// Show start dragged position of image.
var Startpos = $(this).position();
$("div#start").text("START: \nLeft: "+ Startpos.left + "\nTop: " + Startpos.top);
},
// Same as above but prints the current position where MYELEMNT stops
stop: function(event, ui) {
// Show dropped position.
var Stoppos = $(this).position();
$("div#stop").text("STOP: \nLeft: "+ Stoppos.left + "\nTop: " + Stoppos.top);
}
});
我想说它就像写一些类似于我如何获得滑块值的东西一样简单
$( ".static_preview_image" ).css({height: $("input.slider-value").val()});
但我认为我需要使用 cookie...
【问题讨论】:
-
这看起来很适合使用localstorage。
-
现在正在阅读它,这是一种无需使用数据库就可以存储数据的方法吗?
-
好像有点过头了……
-
localstorage 是一个标准 API,用于使用 JavaScript 在 client-side 数据库中存储信息。如果您不希望用户能够转到另一台计算机并访问他们保存的数据,那么这应该可以工作。 HTML5 localstorage 上的这个参考可能更容易理解。
-
很好,我不知道本地存储。听起来是为客户端存储临时数据的好方法。
标签: jquery position save draggable