panorama 0.5.0
Nowadays, there's a lot of websites that are showing huge background images. But loading pictures of that size can have a big impact on performances (this is usually seen when scrolling). Panorama tries to solve this problem by using Canvas2D to lighten images footprint. For an example, take a look at dreamysource.fr, I've used it a lot on this website.
This is compatible with modern browsers and IE > 8.
Note : as stated on caniuse.com, background images in canvas are natively supported on Safari but this feature is not part of any spec
Install
npm install pyrsmk-panorama
bower install pyrsmk-panorama
Use
Quickly :
// Load the image as the background of .some_block;
Panorama handles some options too as its third parameter :
- size : either
contain
orcover
(by default) - attachment :
scroll
(default) orfixed
- left : a
number
in px orcenter
(by default) - top : a
number
in px orcenter
(by default)
// The whole image will be contained in its container;
Since panorama creates a canvas
node in absolute position, you should position your container too (at least with position: relative
).
NOTE : if canvas
is not available on the browser then it fallbacks to background
CSS property
Responsiveness
You can load several images for different dimensions if you need to load responsive images :
;
Promise
You could need to set some actions when the image has been loaded, then you can use the then
promise. Please note that it's a simple promise support. There's no catch
or anything else.
;
Advanced use
If you need to redraw your image into your canvas for any reason, do :
0;
License
Published under the MIT license.