Socket
Socket
Sign inDemoInstall

lazy-blur.js

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lazy-blur.js

Progressive image loader with SVG blur effect


Version published
Weekly downloads
10
increased by233.33%
Maintainers
1
Weekly downloads
 
Created
Source

lazy-blur.js

npm Join the chat at https://gitter.im/Rplus/lazy-blur.js

A progressive image loader library with SVG blur effect.

screenshot for library effect

Usage

steps:

  1. install
  2. image setup
  3. initialize library

Install

You could download this script directly or install via npm.

npm install lazy-blur.js
<script src="lazy-blur.min.js"></script>

Image setup

  • requirement
    • imgRatio, img-width / img-height, unit: %
    • imgS.url
    • imgL.url
  • html markup
    <figure class="image">
      <div class="lazy-blur">
        <div style="padding-bottom: ${imgRatio}"><!-- lazy-blur__imgS__placeholder --></div>
        <img src="${imgS.url}" data-src="${imgL.url}" class="lazy-blur__imgS"/>
        <noscript><img src="${imgL.url}"/></noscript>
      </div>
      <figcaption>something~</figcaption>
    </figure>
    
  • css style
    .lazy-blur {
      position: relative;
      overflow: hidden;
    }
    .lazy-blur img {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
    }
    .lazy-blur__imgL {
      opacity: 0;
      transition: opacity .3s;
    }
    .done > .lazy-blur__imgL {
      opacity: 1;
    }
    
initialize library
new LazyBlur();

Options

All options are optional.

new LazyBlur({
  imgSQuery: ,
  imgLClass: ,
  filterSelector: ,
  getImgLSrc: ,
  onLoad: ,
  blurSize: ,
  scrollThreshold: ,
  eventType:
});
OptionsTypeDefaultDescription
imgSQueryString'.lazy-blur__imgS'query selector of small images.
used in document.querySelectorAll.
imgLClassString'lazy-blur__imgL'class name of large images loaded by lazy-blur.js.
eventTypeString'scroll'The event to active loading large images.
optional: 'scroll', 'click', 'mouseenter'
blurSizeNumber20value of svg gaussian blur filter. larger is more blurred.
scrollThresholdNumber50distance of scroll threshold (buffer), unit: px
filterSelectorString'html.svg *:not(.done) > ' + opt.imgSQuerycss selector for small images with SVG filter.
getImgLSrcFunctionfunction (imgS) { return imgS.getAttribute('data-src'); }function for getting large image's source url.
onLoadFunctionfunction (imgS) { imgS.parentElement.className += ' done '; }callback for large image loaded.

Browser support

License

MIT. © 2015 Rplus

Keywords

FAQs

Package last updated on 25 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc