Im currently stuck on that problem: On my Startpage I have:
<script>
window.addEventListener(
'resize', HideWithResize
)
</script>
and my JS looks terrible I know but I'm just trying stuff:
var HideWithResize = function() {
if ($(window).width() < 1024) {
$('.nav__paragraph--news').hide();
$('.nav__paragraph--abwesend').hide();
document.querySelector(".dropdown__news").classList.replace("dropdown__news--active", "dropdown__news--inactive");
document.querySelector(".dropdown__abwesend").classList.replace("dropdown__abwesend--active", "dropdown__abwesend--inactive");
} else if ($(window).width() > 1024 ) {
$('.nav__paragraph--news').show();
$('.nav__paragraph--abwesend').show();
document.querySelector(".dropdown__news").classList.replace("dropdown__news--inactive", "dropdown__news--active");
document.querySelector(".dropdown__abwesend").classList.replace("dropdown__abwesend--inactive", "dropdown__abwesend--active");
}
};
Let's say someone opens a window on size 1500 and shrinks it below 1024, it should hide 2 paragraphs. when he opens the paragraphes on the smaler window with the dropdown arrows and shrinks the window again (or even increases until 1024) it hides the paragraphs again... But I need it to do only once after going below the limit of 1024... same with someone opening it below 1024 and increasing it over 1024, it always shows the stuff again after resizing
And another thing is that when someone opens the site below 1024 the paragraphs should be hidden, until he opens them --> then they should stay open
Any ideas how that could be solved?
Thanks in advance!
Solution found:
function HideWithResize() {
var prevWidth = 0;
$(document).ready(function() {
prevWidth = $(window).width();
});
$(window).resize(function() {
var currentWidth = $(window).width();
if (prevWidth > 1024 && currentWidth < 1024) {
$('.nav__paragraph--news').hide();
$('.nav__paragraph--abwesend').hide();
document.querySelector(".dropdown__news").classList.replace("dropdown__news--active", "dropdown__news--inactive");
document.querySelector(".dropdown__abwesend").classList.replace("dropdown__abwesend--active", "dropdown__abwesend--inactive");
} else if (prevWidth < 1024 && currentWidth > 1024) {
$('.nav__paragraph--news').show();
$('.nav__paragraph--abwesend').show();
document.querySelector(".dropdown__news").classList.replace("dropdown__news--inactive", "dropdown__news--active");
document.querySelector(".dropdown__abwesend").classList.replace("dropdown__abwesend--inactive", "dropdown__abwesend--active");
}
prevWidth = currentWidth;
});
}