I am facing an issue with my <header>
and <nav>
blocks which are impacted by JavaScript. Is there a way to create a JavaScript solution similar to a media query that would deactivate this JavaScript code if the window width is less than or equal to 1200px?
This is my current JavaScript, running continuously (placed just before </html>
):
<script>
$(window).scroll(function() {
if ($(this).scrollTop()>119)
{
$('header').fadeOut();
$('nav').css({position: 'fixed', top: '0px'});
}
else
{
$('header').fadeIn();
$('nav').css({position: 'absolute', top: 'auto'});
}
});
</script>
I have attempted enclosing the code within
if (document.documentElement.clientWidth <= 1200) {
// scripts
}
and
if (screen.width <= 1200) {
// scripts
}
but without success.