I have a webapp that follows responsive design and has following layout structure. The left layout appears when the window's width > 768px
and right layout shows otherwise.
Based on preliminary research I think there are no modern pure CSS ways of doing it, so I implemented some jQuery code to solve it.
$(window).resize(function() {
if (window.innerWidth > 768) {
fixedHeight = window.innerHeight - $('.search__results').position().top;
$('.search__results').addClass('overflow-y-scroll').height(fixedHeight);
} else {
$('.search__results').removeClass('overflow-y-scroll').height('auto');
}
});
My CSS class is as follows:
.overflow-y-scroll {
overflow-y: scroll;
}
I would like to leave my code up here for review and seek for DRY-er code, some spots I think may be up for improvement.
768px
being fixed, should it be called from a global variable where it is the single point for setting the breakpoints? If so, I wonder where it should be placed so CSS & JavaScript can both use it?
Should I name $('.search__results')
as a variable? Perhaps even make it a more generic helper function? If so, does any one have any tips on how to write it?
I'm also curious as to what is usually the best practice when creating such responsive layouts.