Skip to content
This repository
Browse code

Throttling the resize event prevents small-screen browsers from trigg…

…ering multiple resize events as high-res images are loaded in.
  • Loading branch information...
commit 25db27b1e7caffe0fa9fbf278e6b99565705dd15 1 parent 95ee9ad
Mat Marquis Wilto authored

Showing 1 changed file with 7 additions and 1 deletion. Show diff stats Hide diff stats

  1. +7 1 picturefill.js
8 picturefill.js
@@ -80,7 +80,13 @@
80 80
81 81 // Run on resize and domready (w.load as a fallback)
82 82 if( w.addEventListener ){
83   - w.addEventListener( "resize", w.picturefill, false );
  83 + var throttle;
  84 + w.addEventListener( "resize", function() {
  85 + if( throttle ) { w.clearTimeout( throttle ); }
  86 + throttle = w.setTimeout(function () {
  87 + w.picturefill();
  88 + }, 150 );
  89 + }, false );
84 90 w.addEventListener( "DOMContentLoaded", function(){
85 91 w.picturefill();
86 92 // Run once only

0 comments on commit 25db27b

Scott Jehl

Nice change. Could this line just be w.setTimeout( w.picturefill, 150 ); ?

Please sign in to comment.
Something went wrong with that request. Please try again.