Skip to content
This repository has been archived by the owner on Jan 9, 2022. It is now read-only.

Commit

Permalink
Check if picImg is already a child of matchedEl
Browse files Browse the repository at this point in the history
In working on some local modifications to picturefill (which I hope to submit as a PR at a later time), I noticed some jerkiness when resizing the page. I found that the end action where the code changes the `src` and re-appends the element were the source of the problem.

Since these actions are unnecessary if we are not changing the image, this adds a `continue` if the image's parent node is already `matchedEl`.
  • Loading branch information
PizzaBrandon committed Sep 12, 2013
1 parent 0093678 commit 912d8aa
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions picturefill.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
picImg = w.document.createElement( "img" );
picImg.alt = ps[ i ].getAttribute( "data-alt" );
}
else if( matchedEl === picImg.parentNode ){
// Skip further actions if the correct image is already in place
continue;
}

picImg.src = matchedEl.getAttribute( "data-src" );
matchedEl.appendChild( picImg );
Expand Down

0 comments on commit 912d8aa

Please sign in to comment.