BedrockStreaming / picturefill-background

An inspiration of picturefill using background image and not img tag
23 stars 5 forks source link

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="https://github.com/BedrockStreaming/picturefill-background/raw/master/small.jpg"></span>
    <span data-src="https://github.com/BedrockStreaming/picturefill-background/raw/master/medium.jpg" data-media="(min-width: 400px)"></span>
    <span data-src="https://github.com/BedrockStreaming/picturefill-background/raw/master/large.jpg" data-media="(min-width: 640px)"></span>
    <span data-src="https://github.com/BedrockStreaming/picturefill-background/raw/master/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...