javascript - Page reload sometimes doesn't show a button -


so right i'm making dashboard side-menu collapse-able , reopen-able. works great, except 1 issue. let's collapsed side-menu, , start pressing refresh page on , over, @ speed of 1 click/sec. 2/10 of page reloads not show button supposed there. here's got:

$(document).ready(function () {     $("#home").click(function () {         "use strict";         $.cookie('open', false);         $(this).hide();         $("#home2").show();         $("#nav").slidetoggle('fast');         $(".content").animate({marginleft: "0px"}, 200, function () {});         $(".content").animate({width: "100%"}, 200, function () {});     });      $("#home2").click(function () {         "use strict";         $.cookie('open', true);         $(this).hide();         $("#nav").slidetoggle('fast');         $("#home").show();         $(".content").animate({marginleft: "220px"}, 200, function () {});         $(".content").animate({width: "100%"}, 200, function () {});     });      if ($.cookie('open') === 'false') {          $("#nav").slidetoggle('fast');         $(".content").animate({marginleft: "0px"}, 1, function () {});         $(".content").animate({width: "100%"}, 1, function () {});         $.cookie('open', false);         $("#home").hide();         $("#home2").show();     } }); 

i used cookies state of whether sidebar menu up. when cookie open == false, sidebar closed, , when cookie open == true, opened.

to give more detail, id "home2" 1 not showing of times.

whenever page reload, there's couple of milliseconds can see

    $("#nav").slidetoggle('fast');     $(".content").animate({marginleft: "0px"}, 1, function () {});     $(".content").animate({width: "100%"}, 1, function () {}); 

stuff doing work. whenever happens, button show up. on page reloads, page doesn't , reloads lightning fast can't see mentioned code doing job; when #home2 button decides not pop up, leads me believe stuff in statement not being performed.

this such bizarre problem , have no idea why it's behaving this..

edit: changed if statement around to:

if ($.cookie('open') === 'false') {     $("#home2").show();     $("#home").hide();     $(".content").animate({marginleft: "0px"}, 1, function () {});     $(".content").animate({width: "100%"}, 1, function () {});     $.cookie('open', false);     $("#nav").slidetoggle('fast'); } 

still having same problem.

one option later in page cycle using

$(window).load(function(){      //my code here  });  

instead of document ready; here? api.jquery.com/ready


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -