Permalink
Browse files

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

…ering multiple resize events as high-res images are loaded in.
  • Loading branch information...
1 parent 95ee9ad commit 25db27b1e7caffe0fa9fbf278e6b99565705dd15 @Wilto Wilto committed Jun 23, 2012
Showing with 7 additions and 1 deletion.
  1. +7 −1 picturefill.js
View
@@ -80,7 +80,13 @@
// Run on resize and domready (w.load as a fallback)
if( w.addEventListener ){
- w.addEventListener( "resize", w.picturefill, false );
+ var throttle;
+ w.addEventListener( "resize", function() {
+ if( throttle ) { w.clearTimeout( throttle ); }
+ throttle = w.setTimeout(function () {
+ w.picturefill();
+ }, 150 );
+ }, false );
w.addEventListener( "DOMContentLoaded", function(){
w.picturefill();
// Run once only

0 comments on commit 25db27b

Please sign in to comment.