How to call a function in jQuery on window resize?

后端 未结 2 613
一向
一向 2020-12-10 11:07

I\'ve this code:



        
相关标签:
2条回答
  • 2020-12-10 11:33

    Please call the following method:

    window.dispatchEvent(new Event('resize'));
    
    0 讨论(0)
  • 2020-12-10 11:35

    You can't declare functions that way, use it like this.

    <script>
     $(document).ready(larg);
    
     $(window).resize(larg);
    
     function larg(){
      var larghezza = $(document).width();
      $("p.width").text("The width for the " + larghezza + " is px.");
     }
    </script>
    

    EDIT: changed code a bit, thanks commenters

    0 讨论(0)
提交回复
热议问题