From 67649c8235f88f03e5227b19bd5aecb050cdfe69 Mon Sep 17 00:00:00 2001 From: Lorenzo Boccaccia Date: Fri, 14 Aug 2015 13:46:37 +0200 Subject: [PATCH] Debounced window resize for slower browsers Fixed a race situation between the window size calculation and the resize event in slow browsers by triggering an additional relayout 200ms after the last resize event --- flowtype.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/flowtype.js b/flowtype.js index 5ed5162..15cc984 100644 --- a/flowtype.js +++ b/flowtype.js @@ -40,9 +40,15 @@ // Context for resize callback var that = this; // Make changes upon resize - $(window).resize(function(){changes(that);}); + var to = undefined; + $(window).resize(function(){ + changes(that); + //debounce resizes for slow browser that can't keep up with layout + if (to) clearTimeout(to); + to = setTimeout(function() {changes(that)}, 200); + }); // Set changes on load changes(this); }); }; -}(jQuery)); \ No newline at end of file +}(jQuery));