开发者

Event for resize stopped

开发者 https://www.devze.com 2023-02-18 16:39 出处:网络
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 movement.I just need to know w开

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 movement. I just need to know w开发者_开发技巧hen they've stopped.


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

function onResize(){ ... }

var timer;

$(window).bind('resize', function(){
    if (timer) {
        clearTimeout(timer);
    }

    timer = setTimeout(onResize, 100);
});

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


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

精彩评论

暂无评论...
验证码 换一张
取 消