I have a query regarding window-dependent CSS. It seems to be a common issue, but I am facing some difficulties with it on Wordpress. I am currently using the script recommended by Nettuts. My goal is to apply different CSS styles based on the user's window size. To achieve this, I know that I need to utilize $(window).width(). Here is what I have implemented so far:
function checkWindowSize() {
if ( $(window).width() < 800 ) {
$('body').addClass('small');
}
else {
$('body').removeClass('small');
}
}
$(window).resize(checkWindowSize);
This code works as intended. However, there is a minor issue. When I resize the window to below 800px and then refresh the page with F5, the new CSS style is not applied until I manually resize the window by even just 1px. It does not automatically update when the window is smaller than 800px upon refreshing. I have attempted adjusting the order of the scripts, such as placing the new CSS before the existing CSS, but it did not resolve the problem.
Any suggestions or insights on how to address this issue would be greatly appreciated. If my explanation is unclear, please let me know :)