我做了很多研究,但我需要一个更个性化的答案,我非常肯定保存可拖动的值需要一个 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?
如果那是真的,有人可以解释如何以最干净的方式使用cookies,我只想保存顶部,右侧,左侧,底部的值......
这是我的可拖动功能
$( ".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()});
但我想我需要使用cookies...