Responsive Jquery function not working when window resize

541 views Asked by At

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

There are 2 answers

0
Vhortex On
<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

0
tarun chine On

have you tried writing the function inside resize function

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