KobusH KobusH - 6 days ago 8
Javascript Question

Jquery ignores my if statement

I am working on a little script that hides the navigation when you scroll down and shows the navigation when scroll up.

But for some reason my script ignores the statement.

// the check function

function checkWidth(code) {
$(window).on('resize' , function () {
if( $(window).width() > 1000) {
code

}
})
}

// function I want to use when width is bigger then 1000px

checkWidth(
$(window).bind('mousewheel', function(i) {
if(i.originalEvent.wheelDelta / 120 > 0) {
$('.footer').slideDown();
} else {
$('.footer').slideUp();
}
})
);

Answer

With this code you can run a function if the user is scrolling up or down while the window width is above 1000px. I hope I understood you right.

var winWidth = $(window).width();
$(window).on('resize' , function () {
    winWidth = $(window).width();
});

$(window).on('mousewheel', function(i) {
    if (winWidth > 1000) {
        if (i.originalEvent.wheelDelta / 120 > 0) {
            console.log('scrolling up');
        } else {
            console.log('scrolling down');
        }
    }
});
Comments