Show/hide using jQuery cookies -
so i've created simple tip box fades in on page load, option close box. i'm trying make box hidden if visitor clicks close link. i'm new cookies, i'm doing wrong, have:
$('#close').click(function(e) { jquery.cookie('tip', 'hide', cookieopts); $(this).parent('div.tip').fadeout(1000); e.preventdefault(); }); jquery.cookie('tip', 'show', cookieopts); $('.tip').delay(500).fadein(1000); var shouldshow = jquery.cookie('tip') == 'show'; var cookieopts = {expires: 7, path: '/'}; if( shouldshow ) { $('.tip').delay(500).fadein(1000); } else { $('.tip').css('display', 'none'); }
i revised code:
http://jsbin.com/ujixi4/4/edit
a little bit simpler, achieves want.
var cookieopts = {expires: 7, path: '/'}; //this isnt working reason alert('c: '+$.cookie('tip')); //debug code if( $.cookie('tip') == 'hide'){ //do nothing }else{ $('.tip').delay(500).fadein(1000); //$.cookie('tip', 'hide', {expires: 7, path: '/'}); // add if want cookie disappear on reload (even if don't click) } $('#close').click(function(e) { $.cookie('tip', 'hide', {expires: 7, path: '/'}); $('.tip').hide(); });
here similar awnser using cookies: jquery change font-size based on cookie?
Comments
Post a Comment