Removing the $(window).resize Event in jQuery

后端 未结 2 1259
情书的邮戳
情书的邮戳 2020-12-24 05:13

Part of the page I\'m developing requires a $(window).resize event to be added to a div when a user clicks a button, in order to toggle between resizing it with the window a

2条回答
  •  天涯浪人
    2020-12-24 06:02

    function startResize() {
       $(window).on("resize.mymethod",(function() {
         $("#content").width(newWidth);
         $("#content").height(newHeight);
       }));
    }
    
    function endResize() {
       $(window).off("resize.mymethod");
    }
    

    using a namespace on the query method will allow to to turn off the resize event for you method only.

提交回复
热议问题