1.0.4 • Published 4 years ago

node-background-size v1.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Imitate CSS background-size: cover|cover property in JavaScript.

How to start

npm install node-background-size

Example

<div style="overflow: hidden">
    <img src="image.jpg">
</div>
import { apply } from 'node-background-size';
apply({
    media: document.querySelector("img"),
    rule: 'cover',
    scale: 1
});

Methods

apply

OptionTypeDefaultOptionalDescription
mediaHTMLImageElement | HTMLVideoElement+Media element.
parentHTMLElement+Relative element to which the sizes will be calculated. If undefined, the direct parent will be taken.
rule'cover' | 'contain''cover'+Available values: cover, contain.
scalenumber1+Scaling.

get

OptionTypeDefaultOptionalDescription
mediaHTMLImageElement | HTMLVideoElement+Media element.
rule'cover' | 'contain''cover'+Available values: cover, contain.
scalenumber1+Scaling.
widthnumber500+Container width.
heightnumber500+Container height.

Returns

OptionTypeDescription
mediaHTMLImageElement | HTMLVideoElementThe media element itself.
widthnumberThe calculated width.
heightnumberThe calculated height.
mediaWidthnumberThe initial width of the media element.
mediaHeightnumberThe initial height of the media element.
xnumberThe x-axis coordinate of the top left corner.
ynumberThe y-axis coordinate of the top left corner.
scalenumberScaling.
1.0.4

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago