DOM onresize event

前端 未结 7 527
无人共我
无人共我 2020-12-02 19:06

If I have this

window.onresize = function() {
  alert(\'resized!!\');
};

My function gets fired multiple times throughout the res

相关标签:
7条回答
  • 2020-12-02 19:51

    I liked Pim Jager's elegant solution, though I think that there's an extra paren at the end and I think that maybe the setTimeout should be "timeOut = setTimeout(func,100);"

    Here's my version using Dojo (assuming a function defined called demo_resize())...

    var _semaphorRS = null;
    dojo.connect(window,"resize",function(){
     if (_semaphorRS != null) clearTimeout(_semaphorRS);
     _semaphorRS = setTimeout(demo_resize, 500);
     });
    

    Note: in my version the trailing paren IS required.

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