Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Verlicchi committed Sep 28, 2018
2 parents be42151 + b399afd commit ef41c91
Show file tree
Hide file tree
Showing 16 changed files with 240 additions and 192 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

## Version 10

#### 10.18.0

Added the ability to have multiple background images, through a new `data_bg` option.

#### 10.17.0

Added a new `thresholds` option that you can use when you need to have different thresholds for the scrolling area, so a single `threshold` option is not enough for your needs. Learn more in the API section of the [README](README.md) file.
Added the ability to set different thresholds for the scrolling area, through a new `thresholds` option.

#### 10.16.2

Expand Down
54 changes: 30 additions & 24 deletions README.md

Large diffs are not rendered by default.

307 changes: 155 additions & 152 deletions demos/background_images.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<!DOCTYPE html>
<html>

<head lang="en">
<meta charset="UTF-8">
<title>
Lazyload tests
</title>
<style>
ul, li {
ul,
li {
list-style-type: none;
margin: 0;
padding: 0;
Expand All @@ -17,172 +19,173 @@
width: 220px;
height: 280px;
}

a.multiple {
width: 440px;
background-repeat: no-repeat;
background-position: left, right;
}
</style>
</head>

<body>
<div id="results1" class="results">
<ul>
<li>
<a href="#/it/donna/stivaletti_cod44721746jj.html" data-src="../img/44721746JJ_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/open-toe_cod44740806jx.html" data-src="../img/44740806JX_15_r.jpg"></a>
</li>
<li>
<a href="#/it/donna/sneakers-tennis-shoes-basse_cod44735977gr.html" data-src="../img/44735977GR_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/sneakers-tennis-shoes-basse_cod44738717am.html" data-src="../img/44738717AM_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/sneakers-tennis-shoes-alte_cod44739940cb.html" data-src="../img/44739940CB_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/sneakers-tennis-shoes-alte_cod44740860xg.html" data-src="../img/44740860XG_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/sneakers-tennis-shoes-basse_cod44738719vn.html" data-src="../img/44738719VN_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/sneakers-tennis-shoes-basse_cod44739938wk.html" data-src="../img/44739938WK_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/stivali_cod44736534fq.html" data-src="../img/44736534FQ_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/stivali_cod44735388ui.html" data-src="../img/44735388UI_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44739165ev.html" data-src="../img/44739165EV_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44739454hf.html" data-src="../img/44739454HF_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/stivali_cod44719480km.html" data-src="../img/44719480KM_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44719687td.html" data-src="../img/44719687TD_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/decollete_cod44721899ng.html" data-src="../img/44721899NG_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/mocassini_cod44721744sl.html" data-src="../img/44721744SL_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44716730kr.html" data-src="../img/44716730KR_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/decollete_cod44718734xl.html" data-src="../img/44718734XL_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/decollete_cod44721796uk.html" data-src="../img/44721796UK_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/francesine_cod44717679mj.html" data-src="../img/44717679MJ_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44724594vu.html" data-src="../img/44724594VU_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/decollete_cod44726148aq.html" data-src="../img/44726148AQ_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/mocassini_cod44719629nt.html" data-src="../img/44719629NT_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/mocassini_cod44725329kq.html" data-src="../img/44725329KQ_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/stivali_cod44724026qs.html" data-src="../img/44724026QS_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44720256gw.html" data-src="../img/44720256GW_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44722062id.html" data-src="../img/44722062ID_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/mocassini_cod44722402rh.html" data-src="../img/44722402RH_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44726296vu.html" data-src="../img/44726296VU_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44725755ct.html" data-src="../img/44725755CT_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44725348nv.html" data-src="../img/44725348NV_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44721879xx.html" data-src="../img/44721879XX_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/cuissardes_cod44729472iq.html" data-src="../img/44729472IQ_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/decollete_cod44725388jv.html" data-src="../img/44725388JV_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44721854ce.html" data-src="../img/44721854CE_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/sneakers-tennis-shoes-basse_cod44727690jp.html" data-src="../img/44727690JP_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/mocassini_cod44727501hh.html" data-src="../img/44727501HH_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/sneakers-tennis-shoes-basse_cod44727038aq.html" data-src="../img/44727038AQ_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/mocassini_cod44704882bq.html" data-src="../img/44704882BQ_15_a.jpg"></a>
</li>
<li>
<a href="#/it/donna/mocassini_cod44734002vc.html" data-src="../img/44734002VC_15_a.jpg"></a>
</li>
</ul>
</div>
<script src="../dist/lazyload.min.js"></script>
<script>
(function () {
<div id="results1" class="results">
<ul>
<li>
<a href="#/it/donna/stivaletti_cod44721746jj.html" data-bg="url('../img/44721746JJ_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/open-toe_cod44740806jx.html" data-bg="url('../img/44740806JX_15_r.jpg')"></a>
</li>
<li>
<a href="#/it/donna/sneakers-tennis-shoes-basse_cod44735977gr.html" data-bg="url(../img/44735977GR_15_a.jpg), url(../img/44738717AM_15_a.jpg)"
class="multiple"></a>
</li>
<li>
<a href="#/it/donna/sneakers-tennis-shoes-basse_cod44738717am.html" data-bg="url('../img/44738717AM_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/sneakers-tennis-shoes-alte_cod44739940cb.html" data-bg="url('../img/44739940CB_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/sneakers-tennis-shoes-alte_cod44740860xg.html" data-bg="url('../img/44740860XG_15_a.jpg'),url('../img/44738719VN_15_a.jpg')"
class="multiple"></a>
</li>
<li>
<a href="#/it/donna/sneakers-tennis-shoes-basse_cod44738719vn.html" data-bg="url('../img/44738719VN_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/sneakers-tennis-shoes-basse_cod44739938wk.html" data-bg="url('../img/44739938WK_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/stivali_cod44736534fq.html" data-bg="url('../img/44736534FQ_15_a.jpg'),url('../img/44735388UI_15_a.jpg')"
class="multiple"></a>
</li>
<li>
<a href="#/it/donna/stivali_cod44735388ui.html" data-bg="url('../img/44735388UI_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44739165ev.html" data-bg="url('../img/44739165EV_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44739454hf.html" data-bg="url('../img/44739454HF_15_a.jpg'),url('../img/44719480KM_15_a.jpg')"
class="multiple"></a>
</li>
<li>
<a href="#/it/donna/stivali_cod44719480km.html" data-bg="url('../img/44719480KM_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44719687td.html" data-bg="url('../img/44719687TD_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/decollete_cod44721899ng.html" data-bg="url('../img/44721899NG_15_a.jpg'),url('../img/44721744SL_15_a.jpg')"
class="multiple"></a>
</li>
<li>
<a href="#/it/donna/mocassini_cod44721744sl.html" data-bg="url('../img/44721744SL_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44716730kr.html" data-bg="url('../img/44716730KR_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/decollete_cod44718734xl.html" data-bg="url('../img/44718734XL_15_a.jpg'),url('../img/44721796UK_15_a.jpg')"
class="multiple"></a>
</li>
<li>
<a href="#/it/donna/decollete_cod44721796uk.html" data-bg="url('../img/44721796UK_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/francesine_cod44717679mj.html" data-bg="url('../img/44717679MJ_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44724594vu.html" data-bg="url('../img/44724594VU_15_a.jpg'),url('../img/44726148AQ_15_a.jpg')"
class="multiple"></a>
</li>
<li>
<a href="#/it/donna/decollete_cod44726148aq.html" data-bg="url('../img/44726148AQ_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/mocassini_cod44719629nt.html" data-bg="url('../img/44719629NT_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/mocassini_cod44725329kq.html" data-bg="url('../img/44725329KQ_15_a.jpg'),url('../img/44724026QS_15_a.jpg')"
class="multiple"></a>
</li>
<li>
<a href="#/it/donna/stivali_cod44724026qs.html" data-bg="url('../img/44724026QS_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44720256gw.html" data-bg="url('../img/44720256GW_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44722062id.html" data-bg="url('../img/44722062ID_15_a.jpg'),url('../img/44722402RH_15_a.jpg')"
class="multiple"></a>
</li>
<li>
<a href="#/it/donna/mocassini_cod44722402rh.html" data-bg="url('../img/44722402RH_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44726296vu.html" data-bg="url('../img/44726296VU_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44725755ct.html" data-bg="url('../img/44725755CT_15_a.jpg'),url('../img/44725348NV_15_a.jpg')"
class="multiple"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44725348nv.html" data-bg="url('../img/44725348NV_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44721879xx.html" data-bg="url('../img/44721879XX_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/cuissardes_cod44729472iq.html" data-bg="url('../img/44729472IQ_15_a.jpg'),url('../img/44725388JV_15_a.jpg')"
class="multiple"></a>
</li>
<li>
<a href="#/it/donna/decollete_cod44725388jv.html" data-bg="url('../img/44725388JV_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/stivaletti_cod44721854ce.html" data-bg="url('../img/44721854CE_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/sneakers-tennis-shoes-basse_cod44727690jp.html" data-bg="url('../img/44727690JP_15_a.jpg'),url('../img/44727501HH_15_a.jpg')"
class="multiple"></a>
</li>
<li>
<a href="#/it/donna/mocassini_cod44727501hh.html" data-bg="url('../img/44727501HH_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/sneakers-tennis-shoes-basse_cod44727038aq.html" data-bg="url('../img/44727038AQ_15_a.jpg')"></a>
</li>
<li>
<a href="#/it/donna/mocassini_cod44704882bq.html" data-bg="url('../img/44704882BQ_15_a.jpg'),url('../img/44734002VC_15_a.jpg')"
class="multiple"></a>
</li>
<li>
<a href="#/it/donna/mocassini_cod44734002vc.html" data-bg="url('../img/44734002VC_15_a.jpg')"></a>
</li>
</ul>
</div>
<script src="../dist/lazyload.min.js"></script>
<script>
function logElementEvent(eventName, element) {
console.log(new Date().getTime(), eventName, element.getAttribute('data-src'));
console.log(Date.now(), eventName, element.getAttribute('data-bg'));
}

function logEvent(eventName, elementsLeft) {
console.log(new Date().getTime(), eventName, elementsLeft + " images left");
}

function createImageFragment(srcUrl) {
var imageFragment = document.createElement('img');
imageFragment.setAttribute('src', srcUrl);
return imageFragment;
}

ll = new LazyLoad({
LL = new LazyLoad({
elements_selector: "a",
callback_enter: function (element) {
function callback_load(event) {
element.classList.remove('loading');
logElementEvent("LOADED", element);
imageFragment.removeEventListener('load', callback_load);
}
var imageFragment = createImageFragment(element.getAttribute('data-src'));
imageFragment.addEventListener('load', callback_load);
element.classList.add('loading');
logElementEvent("ENTERED", element);
},
callback_set: function (element) {
logElementEvent("SET", element);
},
callback_error: function(element) {
callback_error: function (element) {
logElementEvent("ERROR", element);
element.src = "https://placeholdit.imgix.net/~text?txtsize=21&txt=Fallback%20image&w=220&h=280";
}
});
}());
</script>
</script>
</body>
</html>

</html>
7 changes: 7 additions & 0 deletions dist/lazyload.amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ define(function () {
data_src: "src",
data_srcset: "srcset",
data_sizes: "sizes",
data_bg: "bg",
class_loading: "loading",
class_loaded: "loaded",
class_error: "error",
Expand Down Expand Up @@ -174,11 +175,17 @@ define(function () {
var setSourcesBgImage = function setSourcesBgImage(element, settings) {
var toWebpFlag = supportsWebp && settings.to_webp;
var srcDataValue = getData(element, settings.data_src);
var bgDataValue = getData(element, settings.data_bg);

if (srcDataValue) {
var setValue = replaceExtToWebp(srcDataValue, toWebpFlag);
element.style.backgroundImage = "url(\"" + setValue + "\")";
}

if (bgDataValue) {
var _setValue = replaceExtToWebp(bgDataValue, toWebpFlag);
element.style.backgroundImage = _setValue;
}
};

var setSourcesFunctions = {
Expand Down
Loading

0 comments on commit ef41c91

Please sign in to comment.