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-sizes

v0.1.3

Published

![npm version](https://badge.fury.io/js/vue-lazy-background-sizes.svg)

Downloads

8

Readme

Vue Lazy Background Sizes

npm version

vue-lazy-background-sizes

A Vue component for lazy loading background images with the ability to load different images based on the window size.

Inspired by Vue Lazy Background Images

Installation

npm install --save vue-lazy-background-sizes

Usage

Import the component

import LazyBackgroundSizes from 'vue-lazy-background-sizes';

Register the component

Vue.component('lazy-background-sizes', LazyBackgroundSizes);

Use the component in the DOM in the following way

<lazy-background-sizes
  :image-sources="[
	"/img/small.jpg",
	"/img/medium.jpg",
	"/img/large.jpg",
  ]"
  loading-image="/img/loading.svg"
  error-image="/img/error.png"
  image-class="lazy-bg"
  background-size="cover"
  :image-success-callback="successCallback"
  :image-error-callback="errorCallback">
</lazy-background-sizes>

The returned html will look like the below

<div data-state="lazy-bg--loaded" class="lazy-bg lazy-bg--loaded" style="background-image: url('http://wordpress.test:3000/wp-content/uploads/2018/06/fff.png'); background-size: cover;"></div>

Props

  • image-sources - An array of image sources (required)
  • loading-image - Path to the loader image (png, svg etc) (optional)
  • error-image - Path to the error image (optional)
  • 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

- Image Sources

The image-sources prop should be an array of images, ordered from smallest to largest in terms of which image you would like to show at the different specified breakpoints.

Multiple images are not required the component will simply start with the first image in the array for small screens and at each break point look for the next image. If there is not another image to show for that screen size the previous image will load.

- Breakpoints

By default the breakpoints where a new image is loaded are 576px and 992px. This means the image-sources prop should contain 3 images to use all of the breakpoints. The first image will be used from 0 - 576px, the second image between 577px and 992px, and finally the third image will be used on screen sizes 993px and greater.

Customizing Break Points

The default screen sizes can be overidden to anything you like, however the numbers must be real numbers without units. (This will be looked at in the future to allow for pixels, rems, view port units and other css units).

To customize the breakpoints simply create a new component and place the vue-lazy-background-sizes component in its mixins property like the following.

import LazyBackgroundSizes from 'vue-lazy-background-sizes';

const MyLazyBackground = {
	mixins: [LazyBackgroundSizes],
	data() {
		return {
			screens: ['762', '1200'],
		}
	},
}

Vue.component('my-lazy-background', MyLazyBackground);

Then use your component in the DOM in the following way

<my-lazy-background
  :image-sources="[
	"/img/small.jpg",
	"/img/medium.jpg",
	"/img/large.jpg",
  ]"
  loading-image="/img/loading.svg"
  error-image="/img/error.png"
  image-class="lazy-bg"
  background-size="cover"
  :image-success-callback="successCallback"
  :image-error-callback="errorCallback">
</my-lazy-background>

TODO's

  • Allow for different unit types in the screens array.
  • Create Example Site.
  • Add the ability to lazy load images based on the scroll position of the element.