Removing the $(window).resize Event in jQuery

后端 未结 2 1262
情书的邮戳
情书的邮戳 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 05:54

    function endResize() {
        $(window).off("resize");
        $("#content").width(originalWidth);
        $("#content").height(originalHeight);
    }
    

    Note that this is extremely obtrusive and might break other code.

    This is better way:

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

提交回复
热议问题