Event for resize stopped

前端 未结 2 1151
清歌不尽
清歌不尽 2021-01-04 01:58

Is there an event that tells me when the user has stopped resizing by letting go of the mouse button? I\'m looking at $(window).resize, and it\'s firing for every pixel mov

相关标签:
2条回答
  • 2021-01-04 02:28

    You can try this :

    function rsizeItems() 
    { }
    
    var tOut = false;
    var milSec = 500;
    $(window).resize(function(){
     if(tOut !== false)
        clearTimeout(tOut);
     tOut = setTimeout(rsizeItems, milSec);
    });
    
    0 讨论(0)
  • 2021-01-04 02:36

    no, but you can defer the event handler if you want:

    function onResize(){ ... }
    
    var timer;
    $(window).bind('resize', function(){
       timer && clearTimeout(timer);
       timer = setTimeout(onResize, 100);
    });
    

    this will make it fire after the user has stopped resizing for 100ms.

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