Browse Source

new plugin

redesign
Anxhelo Lushka 6 years ago
parent
commit
b6772e94b2
No known key found for this signature in database GPG Key ID: 86086158C83770F8
  1. 7
      _includes/footer.html
  2. 2
      _includes/head.html
  3. 14
      index.html
  4. 173
      js/lazyload.js
  5. 2
      js/lazyload.min.js

7
_includes/footer.html

@ -47,10 +47,9 @@
})();
</script>
<script type="text/javascript" charset="utf-8">
window.addEventListener("load", function(event) {
console.log("LOAD!");
lazyload();
<script>
var myLazyLoad = new LazyLoad({
elements_selector: ".lazy"
});
</script>

2
_includes/head.html

@ -49,7 +49,7 @@
<link rel="stylesheet" href="{{ "/css/style.css" | prepend: site.baseurl }}"/>
<link rel="stylesheet" href="{{ "/css/responsive.css" | prepend: site.baseurl }}"/>
<script src="{{ "/js/lazyload.js" | prepend: site.baseurl }}"></script>
<script src="{{ "/js/lazyload.min.js" | prepend: site.baseurl }}"></script>
<script src="{{ "/bower_components/modernizr/modernizr.js" | prepend: site.baseurl }}"></script>
<link rel="canonical" href="{{ page.url | replace:'index.html','' | prepend: site.baseurl | prepend: site.url }}">

14
index.html

@ -126,7 +126,7 @@ clients:
<div class="section-title">
<div class="row">
<div class="medium-10 medium-centered columns">
<img src="images/main/icon.svg" data-src="images/main/icon.svg" alt="" class="lazyload wow flipInY" data-wow-duration="2s" data-wow-delay="0.1s">
<img data-src="images/main/icon.svg" alt="" class="lazy wow flipInY" data-wow-duration="2s" data-wow-delay="0.1s">
<div class="spacing"></div>
<h2>Design, but Open</h2>
</div>
@ -158,7 +158,7 @@ clients:
<div class='large-12 columns'>
<div class='clients'>
{% for client in page.clients %}
<div><a href="{{client.url}}" target="blank"><img alt="" class="lazyload" src="{{site.baseurl}}/{{client.image}}" data-src="{{site.baseurl}}/{{client.image}}" width="200px" height="120px"></a></div>
<div><a href="{{client.url}}" target="blank"><img alt="" class="lazy" data-src="{{site.baseurl}}/{{client.image}}" width="200px" height="120px"></a></div>
{% endfor %}
</div>
</div>
@ -181,7 +181,7 @@ clients:
<div class="quote wow slideInLeft" data-wow-delay="{{ 0.25 | times:forloop.index0 }}s">
<div class="row">
<div class="small-3 columns">
<img class="lazyload" src="{{testimonial.avatar}}" data-src="{{testimonial.avatar}}" width="102px" height="102px" alt="author">
<img class="lazy" data-src="{{testimonial.avatar}}" width="102px" height="102px" alt="author">
</div>
<div class="small-9 columns">
<p>{{testimonial.content}}</p>
@ -196,7 +196,7 @@ clients:
<div class="quote reverse wow slideInRight" class="wow" data-wow-delay="{{ 0.25 | times:forloop.index0 }}s">
<div class="row">
<div class="small-3 columns">
<img class="lazyload" src="{{testimonial.avatar}}" data-src="{{testimonial.avatar}}" width="102px" height="102px" alt="author">
<img class="lazy" data-src="{{testimonial.avatar}}" width="102px" height="102px" alt="author">
</div>
<div class="small-9 columns">
<p>{{testimonial.content}}</p>
@ -226,7 +226,7 @@ clients:
{% for work in page.works_left %}
<div class="work-wrapper">
<a href="{{work.link_to}}" class="work">
<img src="{{site.url}}/{{work.image}}" alt="" class="lazyload">
<img data-src="{{site.url}}/{{work.image}}" alt="" class="lazy">
<div class="info">
<h3>{{work.title}}</h3>
<p>{{work.categories}}</p>
@ -239,7 +239,7 @@ clients:
{% for work in page.works_middle %}
<div class="work-wrapper">
<a href="{{work.link_to}}" class="work">
<img src="{{site.url}}/{{work.image}}" alt="" class="lazyload">
<img data-src="{{site.url}}/{{work.image}}" alt="" class="lazy">
<div class="info">
<h3>{{work.title}}</h3>
<p>{{work.categories}}</p>
@ -252,7 +252,7 @@ clients:
{% for work in page.works_right %}
<div class="work-wrapper">
<a href="{{work.link_to}}" class="work">
<img src="{{site.url}}/{{work.image}}" alt="" class="lazyload">
<img data-src="{{site.url}}/{{work.image}}" alt="" class="lazy">
<div class="info">
<h3>{{work.title}}</h3>
<p>{{work.categories}}</p>

173
js/lazyload.js

@ -1,173 +0,0 @@
/*!
* Lazy Load - JavaScript plugin for lazy loading images
*
* Copyright (c) 2007-2017 Mika Tuupola
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
* Project home:
* https://appelsiini.net/projects/lazyload
*
* Version: 2.0.0-beta.2
*
*/
(function (root, factory) {
if (typeof exports === "object") {
module.exports = factory(root);
} else if (typeof define === "function" && define.amd) {
define([], factory(root));
} else {
root.LazyLoad = factory(root);
}
}) (typeof global !== "undefined" ? global : this.window || this.global, function (root) {
"use strict";
const defaults = {
src: "data-src",
srcset: "data-srcset",
selector: ".lazyload"
};
/**
* Merge two or more objects. Returns a new object.
* @private
* @param {Boolean} deep If true, do a deep (or recursive) merge [optional]
* @param {Object} objects The objects to merge together
* @returns {Object} Merged values of defaults and options
*/
const extend = function () {
let extended = {};
let deep = false;
let i = 0;
let length = arguments.length;
/* Check if a deep merge */
if (Object.prototype.toString.call(arguments[0]) === "[object Boolean]") {
deep = arguments[0];
i++;
}
/* Merge the object into the extended object */
let merge = function (obj) {
for (let prop in obj) {
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
/* If deep merge and property is an object, merge properties */
if (deep && Object.prototype.toString.call(obj[prop]) === "[object Object]") {
extended[prop] = extend(true, extended[prop], obj[prop]);
} else {
extended[prop] = obj[prop];
}
}
}
};
/* Loop through each object and conduct a merge */
for (; i < length; i++) {
let obj = arguments[i];
merge(obj);
}
return extended;
};
function LazyLoad(images, options) {
this.settings = extend(defaults, options || {});
this.images = images || document.querySelectorAll(this.settings.selector);
this.observer = null;
this.init();
}
LazyLoad.prototype = {
init: function() {
/* Without observers load everything and bail out early. */
if (!root.IntersectionObserver) {
this.loadImages();
return;
}
let self = this;
let observerConfig = {
root: null,
rootMargin: "0px",
threshold: [0]
};
this.observer = new IntersectionObserver(function(entries) {
entries.forEach(function (entry) {
if (entry.intersectionRatio > 0) {
self.observer.unobserve(entry.target);
let src = entry.target.getAttribute(self.settings.src);
let srcset = entry.target.getAttribute(self.settings.srcset);
if ("img" === entry.target.tagName.toLowerCase()) {
if (src) {
entry.target.src = src;
}
if (srcset) {
entry.target.srcset = srcset;
}
} else {
entry.target.style.backgroundImage = "url(" + src + ")";
}
}
});
}, observerConfig);
this.images.forEach(function (image) {
self.observer.observe(image);
});
},
loadAndDestroy: function () {
if (!this.settings) { return; }
this.loadImages();
this.destroy();
},
loadImages: function () {
if (!this.settings) { return; }
let self = this;
this.images.forEach(function (image) {
let src = image.getAttribute(self.settings.src);
let srcset = image.getAttribute(self.settings.srcset);
if ("img" === image.tagName.toLowerCase()) {
if (src) {
image.src = src;
}
if (srcset) {
image.srcset = srcset;
}
} else {
image.style.backgroundImage = "url(" + src + ")";
}
});
},
destroy: function () {
if (!this.settings) { return; }
this.observer.disconnect();
this.settings = null;
}
};
root.lazyload = function(images, options) {
return new LazyLoad(images, options);
};
if (root.jQuery) {
const $ = root.jQuery;
$.fn.lazyload = function (options) {
options = options || {};
options.attribute = options.attribute || "src";
new LazyLoad($.makeArray(this), options);
return this;
};
}
return LazyLoad;
});

2
js/lazyload.min.js

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save