简体   繁体   English

调整窗口大小时,不会隐藏“关闭画布”菜单

[英]Off canvas menu is not hidden when resizing the window

Please help!!! 请帮忙!!! Im working on the off canvas menu( https://codepen.io/oleksiukmary/pen/MEGpZj ). 我正在关闭画布菜单上工作( https://codepen.io/oleksiukmary/pen/MEGpZj )。 The problem is when mobile menu is open and user resize the window - content has still transform property and overlay. 问题是当移动菜单打开并且用户调整窗口大小时-内容仍然具有transform属性和叠加。 How can i go back to initial parameters when user resizes the window? 用户调整窗口大小时如何返回初始参数? Should i just check via js if window resize is morethan 768px (my breakpoint) and then hide overlay and transform content? 我是否应该仅通过js检查窗口调整大小是否超过768px(我的断点),然后隐藏覆盖并转换内容?

My js: 我的js:

 $(document).ready(function() {
  $('#nav-toggle').click(function(){
    if($(this).is(":checked")) {
      $('.content-wrap').css('transform', 'translateX(80%)');
    } else {
      $('.content-wrap').css('transform', 'translateX(0)');
    }
    $('body').toggleClass('overflow-hidden');
    $('#c-mask').toggleClass('is-active');
  });

  $('#c-mask').click(function() {
    $('#overlay').fadeOut('slow');
    $(this).removeClass('is-active');
    $('#nav-toggle').prop('checked', false);
    $('.content-wrap').css('transform', 'translateX(0)');
  });
});

Use $( window ).resize(function() to detect the window size and deactivate the offcanvas 使用$( window ).resize(function()来检测窗口大小并停用画布

  $( window ).resize(function() {
if ($(window).width() > 768) {
$('#overlay').fadeOut('slow');
$('#nav-toggle').prop('checked', false);
$('.content-wrap').css('transform', 'translateX(0)');
}
});

Try with this code block 尝试使用此代码块

$( window ).resize(function() {
  if($( window ).width() > 768) {
    $('.content-wrap').css('transform', 'translateX(0)');
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM