npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-lazy-background-images

v1.0.0

Published

Lazy background images. Only background images.

Downloads

460

Readme

Lazy Background Images for Vue

npm version

vue-lazy-background-images

A simple Vue component for lazy loading background components.

This component is only for background images and does not support anything other than that.

Installation

npm install --save-dev vue-lazy-background-images

Usage

Import the component

import VueLazyBackgroundImages from 'vue-lazy-background-images'

Register the component

Vue.component('lazy-background', VueLazyBackgroundImages)

And put into your DOM

<lazy-background
  :image-source="backgroundImage"
  loading-image="/img/loading.svg"
  error-image="/img/error.png"
  image-class="cam-viewport"
  background-size="cover"
  :image-success-callback="successCallback"
  :image-error-callback="errorCallback">
</lazy-background>

And get this out

<div data-width="640" data-height="360" data-state="loaded" class="cam-viewport loaded" style="background-image: url("http://my-site.com/test-image.png"); background-size: cover"></div>

You can see the image-source in the above example is a computed property, although it doesn't have to be.

The callbacks in the above example are bound to data()

Width and height are for the image not the containing div.

Values

  • image-source - The source of the desired image (required)
  • loading-image - Path to the loader image (png, svg etc) (required)
  • error-image - Path to the error image (required)
  • image-class - Any classes you wish to include on the image (optional)
  • background-size - CSS background-size value (optional, default is cover)
  • image-success-callback - Function on success (optional)
  • image-error-callback - Function on error (optional)

Details

Knowing state

The component attaches its state as a class, as well as a data- attribute called state

There are 3 states, loading, loaded, and error

There are no events that get emitted, you can access either the classlist or the dataset to see what state your image is in.

Image size

There will be 2x data- attributes on your rendered - width and height which is the dimensions of the actual image (not the rendered div)

Background size

This is cover by default although it can be overridden.

Callbacks

You can pass in events to trigger on success and failure. These are completely optional and are not required for this to work.

Notes

Contributions welcome, as long as they are related to background images. Enjoy the component