Okay, so this is what I came up with and I would love to get some feedback on this to make this a little more efficient because I'm sure there's room for improvement:
Code:
//Accomodate for window resizing...
var timer = null;
//Does the cookie already have anything?
if($.cookie('font_size').length){
var font_size = $.cookie('font_size');
}else{
var font_size = '';
}
//Accomodate for refresh resizing...
$(window).load(function() {
if($.cookie('res_width').length || $.cookie('res_height').length){
var w = $.cookie('res_width');
var h = $.cookie('res_height');
}else{
var w = $(window).width;
var h = $(window).height;
}
if($.cookie('font_size').length){
font_size = $.cookie('font_size');
}else{
if(w > 1280){font_size = '100%';$.cookie('font_size',font_size);}
if(w < 1280 && w > 1024){font_size = '90%';$.cookie('font_size',font_size);}
if(w < 1024){font_size = '80%';$.cookie('font_size',font_size);}
}
$("#nav ul.links li a").css('font-size', font_size);
return;
});
$(window).resize(function() {
var w = $(window).width();
var h = $(window).height();
$.cookie('font_size', null);
$.cookie('res_width', null);
$.cookie('res_height', null);
$.cookie('res_width', w);
$.cookie('res_height', h);
if(timer != null) clearTimeout(timer);
timer = setTimeout(function(){
if(w > 1280){font_size = '100%';$.cookie('font_size',font_size);$("#nav ul.links li a").animate({fontSize : font_size}, 300);}
if(w < 1280 && w > 1024){font_size = '90%';$.cookie('font_size',font_size);$("#nav ul.links li a").animate({fontSize : font_size}, 300);}
if(w < 1024){font_size = '80%';$.cookie('font_size',font_size);$("#nav ul.links li a").animate({fontSize : font_size}, 300);}
return;
}, 100);
});
The links are the elements I'm resizing the font-size of and right now, I *think* it's basically working but it's just kinda glitchy and I think it has something to do with the setTimeout, but I'm not sure.
Again, I'm just trying to resize a menu along with the resizing of the browser window but I'm trying to set a cookie as per the last resolution / font-size captured so that when the page reloads / refreshes, those last values are captured and used during the page load...
(It's a mess, I know, but it's just where I am right now. So any help here to make it better is very appreciated.)
Bookmarks