2013-07-10 58 views
0

我做了一吨的研究,但我需要一个更加个性化的回答,我非常积极的节约可拖动值需要一个饼干解决方案与jQuery的.slider在那里你可以保存这样jQuery可拖动,重新加载页面后保存位置?

//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()}); 

的价值简单,但我想我需要使用Cookie ...

+1

这看起来很适合使用[localstorage](http://stackoverflow.com/questions/2010892/storing-objects-in-html5-localstorage)。 – DaoWen

+0

现在阅读它,它是一种不使用数据库存储数据的方式吗? –

+0

这似乎有点凌驾于我的头上...... –

回答

1

两种方法:首先,Cookie将在页面刷新之间持续工作。其次,如果您使用PHP,则可以使用客户端会话数据从服务器端记住它,但是此方法要求您在将项目移动到服务器以通知后,通过客户端发送数据(通过ajax或类似的东西)的新位置,所以它可以记住它。

编辑:上面有关使用本地存储听起来像一个很好的方法的意见,我会先尝试。

+0

Cookie和localstorage具有不同的用例。这个答案有一个非常好的描述:http://stackoverflow.com/a/3220802/1427124 – DaoWen

+0

我使用PHP,我实际上需要重用数据,它是管理员端的预览,用户将元素拖动到所需的位置和id喜欢保存页面刷新后的位置,并在前端重复使用.. localstorage听起来很酷,但我确实有一个数据库,听起来我需要使用ajax发送数据,有人可以帮助我,只使用ajax一次.. –

+0

很明显,有很多方法来存储可拖动的数据,但我想要一个简单的解决方案,并且不需要船的代码:) –

相关问题