窗口调整大小时,响应式Jquery功能无效

时间:2021-09-11 19:00:16

After resizing the browser window, this function is not working on first time, but after reload the page, it works.

调整浏览器窗口大小后,此功能第一次不起作用,但重新加载页面后,它可以正常工作。

<script type="text/javascript">
if($(document).width() < 620){
    $(document).ready(function(){
        $(".flexy-menu").flexymenu({
            speed: 400,type: "vertical", indicator: false
        });
    });
}
</script>

Why is it working only after reload ?

为什么它只在重装后才能工作?

2 个解决方案

#1


2  

have you tried writing the function inside resize function

你有没有尝试在resize函数内编写函数

<script>
   $(document).ready(function(){
       $( window ).resize(function() {
          if($(document).width() < 620){            
               $(".flexy-menu").flexymenu({
                      speed: 400,type: "vertical", indicator: false
               });    
           }
        });
    });
 </script>

#2


0  

<script>
$(document).ready(function(){
    if($(document).width() < 620){            
            $(".flexy-menu").flexymenu({
                speed: 400,type: "vertical", indicator: false
            });    
    }
 });
</script>

Have you considered to wait first for the document to be ready? You also missed the starting tag

您是否考虑过先等待文档准备好?你也错过了起始标签

#1


2  

have you tried writing the function inside resize function

你有没有尝试在resize函数内编写函数

<script>
   $(document).ready(function(){
       $( window ).resize(function() {
          if($(document).width() < 620){            
               $(".flexy-menu").flexymenu({
                      speed: 400,type: "vertical", indicator: false
               });    
           }
        });
    });
 </script>

#2


0  

<script>
$(document).ready(function(){
    if($(document).width() < 620){            
            $(".flexy-menu").flexymenu({
                speed: 400,type: "vertical", indicator: false
            });    
    }
 });
</script>

Have you considered to wait first for the document to be ready? You also missed the starting tag

您是否考虑过先等待文档准备好?你也错过了起始标签