Skip to content

Instantly share code, notes, and snippets.

View webjp1's full-sized avatar

Jorge Pirela webjp1

View GitHub Profile
$('.loadPicturePluginClick').click(function(){
$('#lo').loadPicture(function(){
console.log('Picture Loaded');
});
});
<picture id="lo">
<source media="(min-width: 1280px)" data-srcset="./assets/images/compressed/chrome-wallpaper.webp" type="image/webp">
<source media="(min-width: 1280px)" data-srcset="./assets/images/compressed/chrome-wallpaper.jpg" type="image/jpg">
<source media="(min-width: 1152px)" data-srcset="./assets/images/compressed/size-90/chrome-wallpaper.webp" type="image/webp">
<source media="(min-width: 1152px)" data-srcset="./assets/images/compressed/size-90/chrome-wallpaper.jpeg" type="image/jpeg">
<source media="(min-width: 1088px)" data-srcset="./assets/images/compressed/size-85/chrome-wallpaper.webp" type="image/webp">
<source media="(min-width: 1088px)" data-srcset="./assets/images/compressed/size-85/chrome-wallpaper.jpeg" type="image/jpeg">
<source media="(min-width: 1024px)" data-srcset="./assets/images/compressed/size-80/chrome-wallpaper.webp" type="image/webp">
<source media="(min-width: 1024px)" data-srcset="./assets/images/compressed/size-80/chrome-wallpaper.jpeg" type="image/jpeg">
$('.loadImagePluginClick').click(function(){
$('.loadImagePlugin').loadImage(function(){
alert('Image Loaded');
});
});
<img class="loadImagePlugin" style="max-width:100%;" data-src="./assets/images/compressed/chrome-wallpaper.jpg" data-webp="./assets/images/compressed/chrome-wallpaper.webp" alt="Chrome Wallpaper for Lazy Load Example" title="Example Image: Img Tag lazy Load" />
$('.viewportWatcherExampleTrigger').viewportWatcher(function() {
// Element is in the Viewport Do Something
$(this).find('.viewportWatcherExample').fadeIn('slow');
}, function() {
// Element is out of the Viewport Do Other Thing
let display = $(this).css('display');
if (display != "none") {
$(this).find('.viewportWatcherExample').fadeOut('fast');
}
});
<div class="col-100 demo viewportWatcherExampleTrigger">
<div class="viewportWatcherExample" style="width:100%;height:400px;background-color:red;margin:40px 0;display:none;">
</div>
</div>
$('#checkIfIsOnViewport').click(function(){
$('.testToSeeIfIsOnViewport').OnViewport(function(){
// Element is on viewport
// alert("Element Is On Window Viewport");
console.log($(this));
$(this).fadeOut();
},function(){
// Element is not on Viewport
// alert("Element is not on Window Viewport");
console.log($(this));
<div class="testToSeeIfIsOnViewport" style="width:100%;height:400px;background-color:red;margin:40px 0;">
</div>
<button id="checkIfIsOnViewport">
Check If Element is on Viewport
</button>
<iframe data-type="iframe" data-method="click" data-trigger="#loadIframe" data-src="./iframe-lazy-load.html" ></iframe>
<button id="loadIframe">Load Iframe</button>
<iframe data-type="iframe" data-method="viewport" data-src="./iframe-lazy-load.html" ></iframe>