M
M
mrzgt2015-11-09 18:50:47
JavaScript
mrzgt, 2015-11-09 18:50:47

How to make the class hiding work when if ($(window).width() > 960)?

There is JS

$(window).resize(function(){
// Hide mobile menu etc on window resize
 	if ($(window).width() > 960) {
       $('.mobile_menu_wrapper').hide();
 	}

});

With a resolution > 960 it should hide the mobile_menu_wrappe class, but I can't understand if I go to the site with a resolution > 960, it does not hide this class, but when I reduce the browser window to a resolution lower than 960 and then stretch it again, the script works.
How can you correct?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Aksentiev, 2015-11-09
@mrzgt

do the same check on page load

R
Rsa97, 2015-11-09
@Rsa97

Is n't it easier to use css media query ?

M
Maxim Nepritimov, 2015-11-09
@nepritimov_m

Like this for example:

$(function () {
    $(window).resize(function(){
        console.log($(window).width());
        if ($(window).width() > 960) {
           $('.mobile_menu_wrapper').hide();
        } else {
            $('.mobile_menu_wrapper').show();
        }
  });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question