Berawal dari rasa penasaran saya pada tampilan efek loading pada gambar (thumbnail) di beberapa blog, saya pun mencoba mencari tahu caranya untuk membuat tampilan gambar menjadi seperti itu dengan efek-efek keren nan memukau. Mungkin anda juga sering menjumpai tampilan seperti itu pada situs-situs besar atau blog-blog populer.
<script>//<![CDATA[// LazyLoadfunction loadScript(d){var o=document.createElement("script");o.src=d,document.body.appendChild(o)}function downloadJSAtOnload(){loadScript("https://cdn.jsdelivr.net/gh/Arlina-Design/phantom@master/lazyarlinas.js")}window.addEventListener?window.addEventListener("load",downloadJSAtOnload,!1):window.attachEvent?window.attachEvent("onload",downloadJSAtOnload):window.onload=downloadJSAtOnload;//]]></script>
<img expr:alt='data:post.title' expr:src='data:post.firstImageUrl' expr:title='data:post.title' itemprop='image'/>
- tambahkan class='lazy' setelah kode <img ...
- ganti kode src menjadi data-src
- tambahkan kode di bawah ini untuk membuat efek loadingnya:
src='https://flevix.com/wp-content/uploads/2020/01/Preloader.gif'
<img class='lazy' expr:alt='data:post.title' expr:data-src='data:post.firstImageUrl' expr:title='data:post.title' itemprop='image' src='https://flevix.com/wp-content/uploads/2020/01/Preloader.gif'/>
Kalau anda punya gambar animasi loading sendiri, anda bisa ganti link di atas (ditandai warna merah) dengan link gambar gif milik anda. Atau anda juga bisa mencarinya lewat pencarian google, ada banyak gambar animasi untuk efek loading yang bisa anda pakai. Contohnya bisa kunjungi Link ini.
<img class='image' expr:src='data:postFirstImage'/>
Maka tinggal tambahkan saja lazy di belakangnya, sehingga menjadi:
<img class='image lazy' expr:data-src='data:postFirstImage' src='https://flevix.com/wp-content/uploads/2020/01/Preloader.gif'/>
<script type='text/javascript'>//<![CDATA[// Lazy Load(function(a){a.fn.lazyload=function(b){var c={threshold:0,failurelimit:0,event:"scroll",effect:"show",container:window};if(b){a.extend(c,b)}var d=this;if("scroll"==c.event){a(c.container).bind("scroll",function(b){var e=0;d.each(function(){if(a.abovethetop(this,c)||a.leftofbegin(this,c)){}else if(!a.belowthefold(this,c)&&!a.rightoffold(this,c)){a(this).trigger("appear")}else{if(e++>c.failurelimit){return false}}});var f=a.grep(d,function(a){return!a.loaded});d=a(f)})}this.each(function(){var b=this;if(undefined==a(b).attr("original")){a(b).attr("original",a(b).attr("src"))}if("scroll"!=c.event||undefined==a(b).attr("src")||c.placeholder==a(b).attr("src")||a.abovethetop(b,c)||a.leftofbegin(b,c)||a.belowthefold(b,c)||a.rightoffold(b,c)){if(c.placeholder){a(b).attr("src",c.placeholder)}else{a(b).removeAttr("src")}b.loaded=false}else{b.loaded=true}a(b).one("appear",function(){if(!this.loaded){a("<img />").bind("load",function(){a(b).hide().attr("src",a(b).attr("original"))[c.effect](c.effectspeed);b.loaded=true}).attr("src",a(b).attr("original"))}});if("scroll"!=c.event){a(b).bind(c.event,function(c){if(!b.loaded){a(b).trigger("appear")}})}});a(c.container).trigger(c.event);return this};a.belowthefold=function(b,c){if(c.container===undefined||c.container===window){var d=a(window).height()+a(window).scrollTop()}else{var d=a(c.container).offset().top+a(c.container).height()}return d<=a(b).offset().top-c.threshold};a.rightoffold=function(b,c){if(c.container===undefined||c.container===window){var d=a(window).width()+a(window).scrollLeft()}else{var d=a(c.container).offset().left+a(c.container).width()}return d<=a(b).offset().left-c.threshold};a.abovethetop=function(b,c){if(c.container===undefined||c.container===window){var d=a(window).scrollTop()}else{var d=a(c.container).offset().top}return d>=a(b).offset().top+c.threshold+a(b).height()};a.leftofbegin=function(b,c){if(c.container===undefined||c.container===window){var d=a(window).scrollLeft()}else{var d=a(c.container).offset().left}return d>=a(b).offset().left+c.threshold+a(b).width()};a.extend(a.expr[":"],{"below-the-fold":"$.belowthefold(a, {threshold : 0, container: window})","above-the-fold":"!$.belowthefold(a, {threshold : 0, container: window})","right-of-fold":"$.rightoffold(a, {threshold : 0, container: window})","left-of-fold":"!$.rightoffold(a, {threshold : 0, container: window})"})})(jQuery);$(function(){$("img").lazyload({placeholder:"https://flevix.com/wp-content/uploads/2020/01/Preloader.gif",effect:"fadeIn",threshold:"-50"})});//]]></script>
Thanks for reading Cara Membuat Efek Loading Keren Sebelum Gambar Blog Muncul. Please share...!
thanks
BalasHapus