From 585a7b5a3d0fd7fef84066b6a3ec48cc7b3524f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Bonjour?= Date: Fri, 17 Mar 2017 14:24:18 +0100 Subject: [PATCH] Avoid flickering in subsequent calls to `.lazyload()` on items different than that have already been loaded. --- jquery.lazyload.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/jquery.lazyload.js b/jquery.lazyload.js index b395c2e2..9dd0aeb1 100644 --- a/jquery.lazyload.js +++ b/jquery.lazyload.js @@ -89,12 +89,17 @@ self.loaded = false; /* If no src attribute given use data:uri. */ - if ($self.attr("src") === undefined || $self.attr("src") === false) { - if ($self.is("img")) { + if ($self.is("img")) { + if ($self.attr("src") === undefined || $self.attr("src") === false) { $self.attr("src", settings.placeholder); } + } else { + if (!$self.css("background-image")) { + $self.css("background-image", "url('" + settings.placeholder + "')"); + } } + /* When appear is triggered load original image. */ $self.one("appear", function() { if (!this.loaded) {