Cookies lagging

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 23:00:09

问题


I recently asked about how to add cookies to a sidebar menu, and got help by amazing Trincot, here. Found and edited another code to get that to work, now the problem with that code is that it the cookies lag - if you close the sidebar and move to another page, it shows up for a second, then disappears, and considering the entire site's content moves with it, this is incredibly annoying. I think I found a similar question while looking for solution to my previous problem, but I can't remember what I searched for, and haven't been able to re-locate it. I think the fault is with the repetition of the code, but I need to be able to open and close it from two places. Any ideas, anyone?

<script type='text/javascript' src='http://yourjavascript.com/1211131136/jquery.cookie.js'></script>
<script type='text/javascript'>
/**code written by kismet of RPG-Directory.com**/


$(function(){
var website = 'SKY';
var cookie1 = website+'cbox';


if($.cookie(cookie1) === 'on' ||
$.cookie(cookie1) === null){
$('.menu').animate({
left: "-240px"
}, 200);

$('body').animate({
left: "0px"
}, 200); }

else {
$('.menu').animate({
left: "0px"
}, 200);

$('body').animate({
left: "240px"
}, 200); }


$('.icon-close').click(function(){

$.cookie(cookie1, 'on');

$('.menu').animate({
left: "-240px"
}, 200);

$('body').animate({
left: "0px"
}, 200);

});


$('.icon-menu').click(function(){

if($.cookie(cookie1) === 'on' ||
$.cookie(cookie1) === null){

$.cookie(cookie1, 'off');

$('.menu').animate({
left: "0px"
}, 200);

$('body').animate({
left: "240px"
}, 200); }

else {

$.cookie(cookie1, 'on');

$('.menu').animate({
left: "-240px"
}, 200);

$('body').animate({
left: "0px"
}, 200); }

});
});
</script>

Thanks a bunch!

来源:https://stackoverflow.com/questions/33520116/cookies-lagging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!