Here is the code that I am using:
$(document).ready(function() {
$('body').css('overflow', 'scroll');
var heightWithScrollBars = $(window).height();
$('body').css('overflow', 'auto');
alert('heightWithScrollBars = ' + heightWithScrollBars);
if ( heightWithScrollBars < 700 ){
$(".vert, .simply-scroll-clip").height('270px');
}
});
In a linked stylesheet, it is defined that both .vert
and .simply-scroll-clip
elements should have a height of 400px.
Even though when the screen size is less than 700, the if {}
block gets executed, the height change does not happen. Interestingly, if I directly run
$(".vert, .simply-scroll-clip").height('270px');
in the console, it works perfectly fine. But for some reason, it doesn't work when the page loads initially.
Can someone explain why this might be happening?
Thank you!