var vote1 = $('.vote1'),
scrollPrev = 0;
$(window).scroll(function() {
var scrolled = $(window).scrollTop();
if ( scrolled > 100 && scrolled > scrollPrev ) {
vote1.addClass('out');
} else {
vote1.removeClass('out');
}
scrollPrev = scrolled;
});
function myFunction(x) {
if (x.matches) { // If media query matches
var vote1 = $('.vote1'),
scrollPrev = 0;
$(window).scroll(function() {
var scrolled = $(window).scrollTop();
if ( scrolled > 100 && scrolled > scrollPrev ) {
vote1.addClass('out');
} else {
vote1.removeClass('out');
}
scrollPrev = scrolled;
});
}
}
var x = window.matchMedia("(max-width: 500px)")
myFunction(x) // Call listener function at run time
x.addListener(myFunction) // Attach listener function on state changes
let scriptInit = true;
$(window).resize(function() {
$(this).width() > 500 ? scriptInit = true : scriptInit = false;
});
$(window).scroll(function() {
if(scriptInit) {
/* Your Script ... */
var scrolled = $(window).scrollTop();
if ( scrolled > 100 && scrolled > scrollPrev ) {
vote1.addClass('out');
} else {
vote1.removeClass('out');
}
scrollPrev = scrolled;
}
});