Jump to content
  • Sign Up
  • 0

Не всегда срабатывает скрипт


laliev
 Share

Question

Здравствуйте столкнулся с проблемой, не могу понять почему скрипт не всегда срабатывает.  по замыслу это бургер меню которое работает только если ширина окна меньше чем 1025 после загрузки страницы или после ресайза, когда страница загружена результат всегда тот который и ожидался, а после ресайза иногда не срабатывает и меню не открывается, потом после следующего ресайза может заработать , может есть идею в почему так?

 function windowSize(){       myWidth = document.documentElement.clientWidth;     if(myWidth<1025) {         $("button.btn").on("click", function(){            $(".nav-collapse>ul").toggleClass("nav_active");        });            }   }  $(window).on('load resize',windowSize); 

на всякий случай ссылка на сайт и сам скрипт

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

У вас логическая ошибка в скрипте. Ну и если уж и так jQuery используете:

$(function() {  $("button.btn").on("click", function(){    var myWidth = $(window).width();    if (myWidth < 1025) {      $(".nav-collapse > ul").toggleClass("nav_active");    }  });});
И ресайз никакой вам не нужен.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy