我的网站上有一个可拖动的工具栏。但是,如果用户刷新/离开当前页面,工具栏将回到起点。我已经尝试了一些东西,比如将cookie中的X/Y位置保存在cookie中,但没有成功(由于缺乏jQuery/Javascript知识)。保存jCookie中可拖动div的位置/位置
这是我试过到目前为止:
$(document).ready(function() {
var postoolbar = $.jCookies({ get : 'postoolbar' });//Get toolbar position
$(function() {
$("#toolbar").css("margin-left", $('#posX > span').text(xPos));
$("#toolbar").css("margin-top", $('#posy > span').text(yPos));
});
//Draggable toolbar
$(function() {
$("#toolbar").draggable(
{
drag: function(){
var offset = $(this).offset();
var xPos = offset.left;
var yPos = offset.top;
$('#posX > span').text(xPos);
$('#posY > span').text(yPos);
},
stop: function(event, ui) {
$.jCookies({ //Create location toolbar cookie
name : 'postoolbar',
value : { xPos : $('#posX > span').text(xPos), yPos : $('#posY > span').text(yPos)},
hours: 3
});
}
}
);
});
});
检索的cookie:
var postoolbar = $.jCookies({ get : 'postoolbar' });//Get toolbar position
停止我的jQuery的可拖动。
我也很确定我做了CSS错误。
我希望你能帮助我:)
你确定你有jCookies扩展加载。当您加载页面时,控制台中显示什么内容以及何时单击以设置Cookie?您是否验证了Cookie实际上已被设置? – PassKit
我得到这个错误:“TypeError:$ .jCookies不是一个函数”在我检索cookie的线上 – Resitive