Info
Name | Gallery Grid For Angular And Ionic |
Market | codester.com |
Category | JavaScript |
Tags | angular 2, Angular 4, gallery, images, ionic 2, Ionic 3 |
Gallery Grid for Angular v2/v4 and Ionic v2/v3 is the component for integrating responsive gallery into you app (demo)
mama-gallery-grid/src
and paste them into src
folder within your project;app.module.ts
: import { MamaGalleryGrid } from 'path/to/mama-gallery-grid'; ... @NgModule({ declarations: [ ..., MamaGalleryGrid ], ... }) export class AppModule {}
In your view, add:
<!-- Other content --> <mama-gallery-grid> <img *ngFor="let image of images" [src]="image.url" [attr.data-image-width]="image.width" [attr.data-image-height]="image.height"> </mama-gallery-grid> <!-- Other content -->
[breakingRules]
(optional array in format { maxWidth: number, maxColumns: number }[]
) – rules by which images will be broken to rows inside the gallery;maxWidth
– Width of the gallery component;maxColumns
– Number of columns in the gallery when gallery width is lower than maxWidth;Default value:
[ { maxWidth: 480, maxColumns: 1 }, { maxWidth: 1024, maxColumns: 2 }, { maxWidth: Number.MAX_VALUE, maxColumns: 3 } ]
[spacing]
(optional number, default is 0) – spacing between images;data-image-width
and data-image-height
attributes with values set to original dimensions of an image.Currently gallery works same with any HTML element (works with any element that controls sizing through css properties). If you want to implement custom HTML element inside the gallery, do following steps:
ItemAdapter
, ItemStylingOptions
and registerItemAdapter
from mama-gallery-grid
;MyItemAdapter
that implements ItemAdapter
;MyItemAdapter
to registerItemAdapter
;Sample:
import { ItemAdapter, ItemStylingOptions, registerItemAdapter } from 'path/to/mama-gallery-grid'; class MyItemAdapter implements ItemAdapter { styleElement(element:any, options:ItemStylingOptions) { element.widthProperty = `${options.width}px`; element.heightProperty = `${options.height}px`; element.marginTopProperty = `${options.marginTop}px`; element.marginLeftProperty = `${options.marginLeft}px`; element.style.display = 'block'; element.style.float = 'left'; } } registerItemAdapter('my-custom-element', new MyItemAdapter());