Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

background-image templating via data-bgi attr #192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion enabled_background.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ <h2>Plugin enabled on css background images with fadein effect</h2>
<div class="lazy" data-original="img/viper_corner.jpg" style="width: 765px; height: 574px; background-image: url('img/grey.gif')"></div>
<div class="lazy" data-original="img/bmw_m3_gt.jpg" style="width: 765px; height: 574px; background-image: url('img/grey.gif')"></div>
<div class="lazy" data-original="img/corvette_pitstop.jpg" style="width: 765px; height: 574px; background-image: url('img/grey.gif')"></div>
<div class="lazy" data-original="img/corvette_pitstop.jpg" data-bgi="linear-gradient(to bottom, rgba(255,0,0,0) 0%, rgba(255,0,0,0) 70%,rgba(0,0,0,0.8) 100%), url('LAZYURL')" style="width: 765px; height: 574px; background-image: url('img/grey.gif')"></div>

</div>
</div>
Expand Down Expand Up @@ -120,4 +121,4 @@ <h5 class="title">ABOUT</h5>
});
</script>
</body>
</html>
</html>
4 changes: 4 additions & 0 deletions jquery.lazyload.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
effect : "show",
container : window,
data_attribute : "original",
bgi_attribute : "bgi",
skip_invisible : true,
appear : null,
load : null,
Expand Down Expand Up @@ -106,9 +107,12 @@
.bind("load", function() {

var original = $self.attr("data-" + settings.data_attribute);
var bgi = $self.attr("data-" + settings.bgi_attribute);
$self.hide();
if ($self.is("img")) {
$self.attr("src", original);
} else if ( typeof bgi !== 'undefined' ) {
$self.css("background-image", bgi.replace('LAZYURL',original));
} else {
$self.css("background-image", "url('" + original + "')");
}
Expand Down