Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

picturefill-background

Package Overview
Dependencies
Maintainers
5
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

picturefill-background

A Responsive Images approach like Picturefill but managing a picture on background-image css attribute.

latest
Source
npmnpm
Version
1.0.3
Version published
Weekly downloads
167
-10.7%
Maintainers
5
Weekly downloads
 
Created
Source

Picturefill-background

A Responsive Images approach like Picturefill but managing a picture on background-image css attribute.

Note: Picturefill-background works best in browsers that support CSS3 media queries..

Markup pattern and explanation

Mark up your responsive images like this.

<div class="picturefill-background">
    <span data-src="small.jpg"></span>
    <span data-src="medium.jpg" data-media="(min-width: 400px)"></span>
    <span data-src="large.jpg" data-media="(min-width: 640px)"></span>
    <span data-src="big.jpg" data-media="(min-width: 800px)"></span>
</div>

Default options

w.picturefillBackgroundOptions = {
    selector: "picturefill-background",
    backgroundSize: "cover",
    backgroundRepeat: "no-repeat",
    backgroundPosition: "50% 50%"
};

Redefine this value to replace some of the options

picturefillBackgroundOptions.selector = "custom-selector";

Explained...

Notes on the markup above...

  • The div[class="picturefill-background"] element is used to apply background-image attribute.
  • The div[class="picturefill-background"] element can contain any number of div[data-source] elements.
  • Each div[data-src] element must have a data-src attribute specifying the image path.
  • Each div[data-src] element can have an optional [data-media] attribute to make it apply in specific media settings. Both media types and queries can be used, like a native media attribute, but support for media queries depends on the browser (unsupported browsers fail silently).
  • The matchMedia polyfill is required to support the data-media attribute in older browsers (e.g. IE9, Android 2.3 Browser). See http://caniuse.com/#feat=matchmedia for a table detailing native support for the matchMedia API.

Keywords

picture

FAQs

Package last updated on 15 May 2019

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