1.0.3 • Published 9 years ago

famous-bkimagesurface v1.0.3

Weekly downloads
1
License
-
Repository
github
Last release
9 years ago

famous-bkimagesurface

BkImageSurface adds support for sizing-strategies such as AspectFit and AspectFill for displaying images with famo.us. It uses a 'div' with a background-image rather than a 'img' tag.

Can be used as a drop-in replacement for ImageSurface, in case the size of the div is not derived from the image.

Demo

View the demo here

Getting started

Install using bower or npm:

bower install famous-bkimagesurface

npm install famous-bkimagesurface

Example of how to create a BkImageSurface:

var BkImageSurface = require('famous-bkimagesurface');

var imageSurface = new BkImageSurface({
    content: 'myimage.png',
    sizeMode: BkImageSurface.SizeMode.ASPECTFILL
});
this.add(imageSurface);

all possible modes:

var imageSurface = new BkImageSurface({
    content: 'myimage.png',
    sizeMode: BkImageSurface.SizeMode.ASPECTFILL,
    positionMode: BkImageSurface.PositionMode.TOP,
    repeatMode: BkImageSurface.RepeatMode.NONE
});
this.add(imageSurface);

using css-style values directly:

var imageSurface = new BkImageSurface({
    content: 'myimage.png',
    sizeMode: '100px 50%',
    positionMode: 'center center',
    repeatMode: 'repeat-x'
});
this.add(imageSurface);

using the setter-functions:

var imageSurface = new BkImageSurface();
imageSurface.setContent('http://www.myimage.png');
imageSurface.setSizeMode(BkImageSurface.SizeMode.ASPECTFIT);
imageSurface.setPositionMode(BkImageSurface.PositionMode.RIGHT);
imageSurface.setRepeatMode(BkImageSurface.RepeatMode.VERTICAL);

Documentation

The size-, position- and repeat- modes correspond directly to the following css-styles:

ModeCSS-style
SizeModebackground-size
PositionModebackground-position
RepeatModebackground-repeat

According to your liking you can choose to use either the Mode-definitions or CSS-styles directly.

Size-modes

ModeValueDescription
SizeMode.AUTOautoKeeps the original image dimensions.
SizeMode.FILL (default)100% 100%Fills the image to the size of the div.
SizeMode.ASPECTFILLcoverFills the div with the image while keeping correct image aspect ratio (crops if neccesary).
SizeMode.ASPECTFITcontainFits the whole image in the div while keeping correct image aspect ratio.

Position-modes

ModeValueDescription
PositionMode.CENTER (default)center centerCenters the image in the div.
PositionMode.LEFTleft centerLeft aligns the image in the div.
PositionMode.RIGHTright centerRight aligns the image in the div.
PositionMode.TOPcenter topTop aligns the image in the div.
PositionMode.BOTTOMcenter bottomBottom aligns the image in the div.
PositionMode.TOPLEFTleft topAligns the image in the top-left corner of the div.
PositionMode.TOPRIGHTright topAligns the image in the top-right corner of the div.
PositionMode.BOTTOMLEFTleft bottomAligns the image in the bottom-left corner of the div.
PositionMode.BOTTOMRIGHTright bottomAligns the image in the bottom-right corner of the div.

Repeat-modes

ModeValueDescription
RepeatMode.NONE (default)no-repeatNo image-repeat.
RepeatMode.HORIZONTALrepeat-yImage is repeated horizontally.
RepeatMode.VERTICALrepeat-xImage is repeated vertically.
RepeatMode.BOTHrepeatImage is repeated both horizontally and vertically.

API reference

ClassDescription
BkImageSurfaceBackground image surface class.

Contribute

Feel free to contribute to this project in any way. The easiest way to support this project is by giving it a star.

Contact

  • @IjzerenHein
  • http://www.gloey.nl
  • hrutjes@gmail.com

© 2014 - Hein Rutjes

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

10 years ago

1.0.0

10 years ago