/ Published in: jQuery
I've previously posted this here: http://snipplr.com/view/59044/flexible-site-layout-with-resize-detection/
This new version is short and more efficient, plus it no longer shows 1 (harmless) error on launch. Works the same as last time, the sizable object has the size to add the class too all the sizable elements, so for this example if the screen is less that 450px it'll add the class "phone" to the body (and the other elements), and if it's larger than 750px, but not 1000px, it'll give it the tablet layout. More information about the script is at the link, questions/comments/concerns can be sent to be from here or the comments section at the link.
This new version is short and more efficient, plus it no longer shows 1 (harmless) error on launch. Works the same as last time, the sizable object has the size to add the class too all the sizable elements, so for this example if the screen is less that 450px it'll add the class "phone" to the body (and the other elements), and if it's larger than 750px, but not 1000px, it'll give it the tablet layout. More information about the script is at the link, questions/comments/concerns can be sent to be from here or the comments section at the link.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var sizeable = 'body,#master,#content,#posts,#sidebar,#footer,#comments'; var sizes = {'450':'phone','750':'tablet','1000':'desktop'}; $(document).ready(function(){ $(window).resize(); }); $(window).resize(function(classes){ $.each(sizes,function(k,v){ var w = parseInt($(window).width()); if(w>=k){ $(sizeable).removeClass().addClass(v); } }); });
URL: http://fatfolderdesign.com/488/css/better-flexible-site-layout-with-resize-detection