基于JS的解决方案是不是很好(阅读),但无论如何,我会尝试先回答关于饼干的问题:
你可以使用某种jQuery cookie plugin或只是简单的JS的是有点困难。 jQuery的语法是:
$.cookie('name', 'value'); // storing cookie
$.cookie('name'); // reading cookie
使用,你可以在你的源代码更改为类似这样:
function resizeContainer(var force=false) // additional parameter is used to force resetting cookie
{
var width;
if($.cookie('knownWidth') && !force) // if there's a cookie and we're not forcing reset, use width from cookie
{
width = $.cookie('knownWidth');
}
else
{
width = $(window).width();
$.cookie('knownWidth', width);
}
var bodycontent_grid = width < 1200 ? 'span8' :
width > 1200 ? 'span6' : '';
rightcol_grid = width < 1200 ? 'span3' :
width > 1200 ? 'span5' : '';
$('.bodycontent').removeClass('span6 span8').addClass(bodycontent_grid),
$('.rightcol').removeClass('span3 span5').addClass(rightcol_grid);
}
$(window).bind("load", function(){
resizeContainer(); // onload use cookie
});
$(window).bind("resize", function(){
resizeContainer(true); // when resizing force changing the cookie
});
五言中,该cookie可以在服务器端进行访问,然后可以产生容器在服务器端有适当的类。
我必须说我不喜欢使用cookie的解决方案。有很多人在谈论responsive web design,那么为什么不使用CSS @media-queries?
你可以做这样的事情在你的.css文件:
@media only screen and (min-width : 1200px) {
/* Styles when over 1200px */
}
@media only screen and (max-width: 1199px) {
/* Styles when under 1200px */
}
顺便说一句,尝试调整浏览器窗口,当你在http://bostonglobe.com/或http://smashingmagazine.com :)这是纯CSS!