我的網站上有一個可拖動的工具欄。但是,如果用戶刷新/離開當前頁面,工具欄將回到起點。我已經嘗試了一些東西,比如將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