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

@sunnysideup/stretched-bg-image

v5.4.2

Published

NPM package - adds a stretched (filling) BG image to any html element where you add the 'stretched-bg-image' class

Downloads

7

Readme

Stretched Background Images

NPM package - adds a stretched (filling) BG image to any html element where you add the "stretched-bg-image" class.

credits

For examples images in demo, see demo. Idea and design for squiggly images is by Niels from Guts

Also See

Installation // new-school

Install via npm:

npm i @sunnysideup/stretched-bg-image

Add the following code to your js file:

import StretchedBgImages from 'stretched-bg-images'

And, add the following code to your scss file:

import "StretchedBgImages";

Installation // old-school

Add the following code to your html:

<link rel="stylesheet" href="stretched-bg-images/src/css/StretchedBgImages.css" />
...
<script src="stretched-bg-images/src/js/StretchedBgImages.js"></script>
<script>
  // add script here!
</script>

Applying it to your page ...

To apply it to any element, use the stretched-bg-images class, like this:

<div class="stretched-bg-images">
  ...
</div>

Running it

Add the following JS (old and new school):

StretchedBgImages.apply()

Or with all options defined:

const options = {

queryString: '.stretched-bg-images, ul',

errorClass: 'ratio-is-off-the-charts',

classRanges = [
  {
    max: '8',
    min: '2',
    className: 'panorama'
  },
  {
    max: '2',
    min: '1',
    className: 'landscape'
  },
  {
    max: '1',
    min: '0.5',
    className: 'portrait'
  },
  {
    max: '0.5',
    min: '0.125',
    className: 'skyscraper'
  }
]
}
StretchedBgImages.apply(options)

Options

  • Above you are seeing the default values, you can set them as you see fit.
  • max and min refer the maximum and minimum aspect ratio defined as width divided by height (i.e. 8 means that the width is four times greater than the height of the containing box.)
  • queryString can be anything that works with: document.querySelectorAll.
  • errorClass is the class that is added when the ratio of the element is outside the described scopes in classRanges.

Using SVGs

If you are using SVGs then you need to remove width and height attributes from SVG and add preserveAspectRatio="none". Like this:

<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="none" viewBox="0 0 123 456">...</svg>

You can use https://yoksel.github.io/url-encoder/ to convert SVGs to backround images. Making your code even faster.