How to use lozad - 10 common examples

To help you get started, we’ve selected a few lozad examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apache / incubator-dlab / src / js / init.js View on Github external
/*jslint browser: true, white: true, plusplus: true, regexp: true, indent: 4, maxerr: 50, es5: true */
/*jshint multistr: true, latedef: nofunc */
/*global jQuery, $, Swiper*/

import $ from 'jquery';
import Swiper from "swiper";
import screen from './lib';
import lozad from "lozad";

// lazy loads elements with default selector as ".lozad"
const observer = lozad();
observer.observe();

var macSwiper,
    screenSliderTop,
    macNavigation = $('.controls-nav'),
    screenThumbsNavigation = $('.screen-slider-thumbs');
$(document).ready(function() {
    $('body').show();
    $('#msg').hide();
    window.scrollTo(window.scrollX, window.scrollY + 1);
    window.scrollTo(window.scrollX, window.scrollY - 1);
});

function stopMacVideos() {
    'use strict';
    $('.mac-wrap .swiper-slide video').each(function () {
github calpa / gatsby-starter-calpa-blog / src / components / Content / index.js View on Github external
componentDidMount() {
    // lazy loads elements with default selector as '.lozad'
    // Prevent WebPack build fail
    if (isBrowser()) {
      // Initialize library
      const observer = lozad('.lozad', {
        load(el) {
          /* eslint-disable no-param-reassign */

          el.src = el.dataset.src;
          el.onload = () => {
            el.classList.add('animated');
            el.classList.add('fadeIn');
          };
          /* eslint-enable */
        },
      });
      observer.observe();
    }
  }
github DivanteLtd / storefront-ui / packages / vue / src / components / molecules / SfGallery / SfGallery.js View on Github external
mounted() {
    // handle slider with swipe and transitions with Glide.js
    // https://glidejs.com/docs/
    const glide = new Glide(this.$refs.glide, this.sliderOptions);
    glide.on("run", () => {
      this.go(glide.index);
    });
    glide.mount();
    this.glide = glide;
    // handle lazy load for big images with lozad
    // https://apoorv.pro/lozad.js/
    const observer = lozad(".sf-gallery__big-image");
    observer.observe();
  },
github radio-t / radio-t-site / hugo / src / js / controllers / avatars_controller.js View on Github external
connect() {
    super.connect();
    lozad(this.element, {
      load: async () => {
        this.element.classList.add('loaded');
        const {data} = await this.getComments();
        const pictures = uniq(filter(map(data.comments, 'user.picture'))).reverse();
        this.element.innerHTML = '';
        pictures.slice(0, limit).forEach((picture, index) => {
          if (!picture) return;
          const div = document.createElement('DIV');
          div.style.backgroundImage = `url('${picture}')`;
          div.classList.add('comments-counter-avatars-item');
          div.style.transitionDelay = `${(limit - index) * 20}ms`;
          this.element.appendChild(div);
        });
        // todo limit waiting time before showing images
        imagesLoaded(this.element, {background: '.comments-counter-avatars-item'}, () => {
          this.reflow();
github saberland / saber / packages / saber-plugin-image / lib / saber-browser.js View on Github external
mounted() {
      const { $el } = this

      if ($el.dataset.src || $el.dataset.srcset) {
        lozad($el, {
          loaded: el => {
            el.addEventListener(
              'load',
              () => {
                el.setAttribute('data-lazy-loaded', '')
                el.addEventListener(
                  'transitionend',
                  () => {
                    el.classList.remove(styles.blendIn)
                  },
                  { once: true }
                )
              },
              { once: true }
            )
          }
github htmlburger / wpemerge-theme / resources / scripts / frontend / lazyload.js View on Github external
import 'intersection-observer';
import lozad from 'lozad';

const observer = lozad();
observer.observe();
github fusioncms / fusioncms / fusion / resources / js / components / file-manager / Image.vue View on Github external
mounted() {
            this.$refs.image.addEventListener('load', this.doneLoading())

            this.$once('hook:destroyed', () => {
                if (this.$refs.image) {
                    this.$refs.image.removeEventListener('load', this.doneLoading())
                }
            })

            this.lozad = lozad(this.$refs.image)
            
            this.lozad.observe()
        },
    }
github DivanteLtd / storefront-ui / packages / react / src / components / atoms / SfImage / index.jsx View on Github external
useEffect(() => {
    if (props.lazy !== false && ref) {
      const observer = lozad(ref.current, {
        loaded: () => {
          setLoaded(true);
        },
      });
      observer.observe();
    } else {
      setLoaded(true);
    }
  }, [props.src]);
github DivanteLtd / storefront-ui / packages / vue / src / components / atoms / SfImage / SfImage.js View on Github external
mounted() {
    if (this.lazy !== false) {
      const vm = this;
      const observer = lozad(vm.$refs.imgLazy, {
        loaded: function() {
          vm.loaded = true;
        }
      });
      observer.observe();
    } else {
      this.loaded = true;
    }
  }
};
github calpa / gatsby-starter-calpa-blog / src / pages / stats.js View on Github external
componentDidMount() {
    const observer = lozad();
    observer.observe();
  }

lozad

A light-weight JS library to lazy load any HTML element such as images, ads, videos etc.

MIT
Latest version published 2 years ago

Package Health Score

61 / 100
Full package analysis

Popular lozad functions