jQuery - 窗口调整大小;后 [英] jQuery - Window resize; after

查看:69
本文介绍了jQuery - 窗口调整大小;后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用jQuery的调整大小功能,但是由于我在调整大小时所做的调整,因为它在每次调整时都会发光,所以会让它看起来很平滑。

I am currently using jQuery's resize function, but because of what I adjust on resize, there's simply too much going on to make it look smooth, as it fires at every adjustment.

$(window).resize(function() {

myFunction();

});

有没有办法在调整大小停止后关闭某个功能?喜欢$(window).afterResize()还是什么?

Is there a way to fire a function off after the resize has stopped? Like $(window).afterResize() or something?

欢迎任何解决方案。

推荐答案

我不确定是否有是一个'干净'的本地方式来做到这一点(希望有,有人会光明)

I am not sure if there is a 'clean' native way to do it (hopefully there is and someone will shed light)

但你像这样破解 http://jsfiddle.net/tuuN3/

var myInterval = false; // this variable will hold the interval and work as a flag
var $win = $(window); //jquery win object
var dimensions = [ $win.width(), $win.height() ]; //initial dimensions

$(window).resize(function() { //on window resize...

    if( !myInterval ) //if the interval is not set,
    {
        myInterval  = setInterval( function() { //initialize it
            //and check to see if the dimenions have changed or remained the same
            if( dimensions[ 0 ] === $win.width() && dimensions[ 1 ] ===  $win.height() )
            {   //if they are the same, then we are no longer resizing the window
                clearInterval( myInterval ); //deactivate the interval
                myInterval = false; //use it as a flag

                doStuff(); //call your callback function
            }
            else
            {
                 dimensions[ 0 ] =    $win.width(); //else keep the new dimensions
                 dimensions[ 1 ] =    $win.height();
            }
        }, 64 );  //and perform a check every 64ms
    }

});

这篇关于jQuery - 窗口调整大小;后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆