@casus-campus/ngx-gallery v0.8.0
This project was generated with Angular CLI version 8.2.0 and is a hard fork of https://github.com/lukasz-galka/ngx-gallery (hard fork because we need a angular library generated with the cli).
Create a library structure with instructions of this article.
- Library:
projects/ngx-gallery
- Test App:
projects/lib-tester
NgxGallery
Angular image gallery plugin
Use this hard fork for development
Set up
Setup Fork
- clone via custom bitbucket link
- install dependencies with
npm install
- build dist folder with
npm run build
Setup project, that uses this library
- install the ngx-gallery fork with
npm i ../cc-ngx-gallery/dist/ngx-gallery/casus-campus-ngx-gallery-x.y.z.tgz
(inside the base folder of the other project) - add following scripts to file angular.json (or similar):
node_modules/jquery/dist/jquery.js
undnode_modules/flowplayer/dist/flowplayer.js
- add following style sheets to file angular.json (or similar):
node_modules/font-awesome/css/font-awesome.css
undnode_modules/flowplayer/dist/skin/skin.css
- install
jquery
andflowplayer
in project, that uses this library - add option
"aot": true,
to angular.json (projects->->architect->build->option and projects->->configurations->productions) - add to option
assets
of angular.json: { "glob": "*/", "input": "./node_modules/@casus-campus/ngx-gallery/assets", "output": "./assets/" }
Development
- start in branch
develop
(git checkout develop
) - create new feature branch (
git checkout -b feature/f-1
) - start building dist files during development with
npm run build:watch
- commit changes
- when finished: merge into develop with
git checkout develop && git merge feature/f-1
Publish library to NPM
Publishing the library is only needed, if the develop
branch has some changes that are not already in the production
branch. The latest production
commit reflects the latest published version on NPM.
Perform following steps to publish a new version to NPM:
- make sure that
develop
branch is checked out (git checkout develop
) - make sure that the tests succeed (
ng test @casus-campus/ngx-gallery
) - increase version in
./projects/ngx-gallery/package.json
(following SemVer) - commit and push changes
- merge into production (
git checkout production && git merge develop
) - push changes (
git push
)
Demo
Playground
You can play with gallery using Plunker or CodePen
Prerequisites
- Font Awesome (required for icons)
npm install font-awesome --save
For angular-cli based projects insert styles into .angular-cli.json
"styles": [
...
"../node_modules/font-awesome/css/font-awesome.css"
]
- Hammerjs (required for swipe)
npm install hammerjs --save
import 'hammerjs';
SystemJS
If you are not using SystemJS you can skip this section.
map: {
'ngx-gallery': 'node_modules/ngx-gallery/bundles/ngx-gallery.umd.js',
}
Angular Material
If you are not using Angular Material you can skip this section.
Angular Material is using transform: translate3d(0,0,0);
in components styles. Unfortunately transform
changes positioning context and preview won't work properly. To avoid this situation you have to override material styles, for example:
@import "~@angular/material/prebuilt-themes/indigo-pink.css"; // your theme
.mat-sidenav-container, .mat-sidenav-content, .mat-tab-body-content {
transform: none !important;
}
You can read more about this issue here
Installation
npm install ngx-gallery --save
NgxGalleryOptions
All names of ccp extended options have a prefix ccp
width
| Type:string
| Default value:'500px'
- gallery widthheight
| Type:string
| Default value:'400px'
- gallery heightbreakpoint
| Type:number
| Default value:undefined
- responsive breakpoint, works like media query max-widthfullWidth
| Type:boolean
| Default value:false
- sets the same width as browserlayout
| Type:string
| Default value:NgxGalleryLayout.Bottom
- sets thumbnails positionstartIndex
| Type:number
| Default value:0
- sets index of selected image on startlinkTarget
| Type:string
| Default value:_blank
- sets target attribute of linklazyLoading
| Type:boolean
| Default value:true
- enables/disables lazy loading for imagesimage
| Type:boolean
| Default value:true
- enables or disables imageimageDescription
| Type:boolean
| Default value:true
- enables or disables description for imagesimagePercent
| Type:number
| Default value:75
- percentage heightimageArrows
| Type:boolean
| Default value:true
- enables or disables arrowsimageArrowsAutoHide
| Type:boolean
| Default value:false
- enables or disables arrows auto hideimageSwipe
| Type:boolean
| Default value:false
- enables or disables swipeimageAnimation
| Type:string
| Default value:NgxGalleryAnimation.Fade
- animation typeimageSize
| Type:string
| Default value:NgxGalleryImageSize.Cover
- image sizeimageAutoPlay
| Type:boolean
| Default valuefalse
- enables or disables auto playimageAutoPlayInterval
| Type:number
| Default value:2000
- interval for auto play (ms)imageAutoPlayPauseOnHover
| Type:boolean
| Default value:false
- enables or disables pouse auto play on hoverimageInfinityMove
| Type:boolean
| Default value:false
- enables or disables infinity move by arrowsimageActions
| Type:NgxGalleryAction[]
| Default value:[]
- Array of custom actionsimageBullets
| Type:boolean
| Default value:false
- enables or disables navigation bulletsccpImageAsLink
| Type:boolean
| Default value:false
- enables or disables links on imagethumbnails
| Type:boolean
| Default value:true
- enables or disables thumbnailsthumbnailsColumns
| Type:number
| Default value:4
- columns countthumbnailsRows
| Type:number
| Default value:1
- rows countthumbnailsPercent
| Type:number
| Default value:25
- percentage heightthumbnailsMargin
| Type:number
| Default value:10
- margin between thumbnails and imagethumbnailsArrows
| Type:boolean
| Default value:true
- enables or disables arrowsthumbnailsArrowsAutoHide
| boolean:string
| Default value:false
- enables or disables arrows auto hidethumbnailsSwipe
| Type:boolean
| Default value:false
- enables or disables swipethumbnailsMoveSize
| Type:number
| Default value:1
- number of items to move on arrow clickthumbnailsOrder
| Type:number
| Default value:NgxGalleryOrder.Column
- images orderthumbnailsRemainingCount
| Type:boolean
| Default value:false
- if true arrows are disabled and last item has label with remaining countthumbnailsAsLinks
| Type:boolean
| Default value:false
- enables or disables links on thumbnailsthumbnailMargin
| Type:number
| Default value:10
- margin between images in thumbnailsthumbnailSize
| Type:string
| Default value:NgxGalleryImageSize.Cover
- thumbnail sizethumbnailActions
| Type:NgxGalleryAction[]
| Default value:[]
- Array of custom actionspreview
| Type:boolean
| Default value:true
- enables or disables previewpreviewDescription
| Type:boolean
| Default value:true
- enables or disables description for imagespreviewSwipe
| Type:boolean
| Default value:false
- enables or disables swipepreviewFullscreen
| Type:boolean
| Default value:false
- enables or disables fullscreen iconpreviewForceFullscreen
| Type:boolean
| Default value:false
- enables or disables opening preview in fullscreen modepreviewCloseOnClick
| Type:boolean
| Default value:false
- enables or disables closing preview by clickpreviewCloseOnEsc
| Type:boolean
| Default value:false
- enables or disables closing preview by esc keyboardpreviewKeyboardNavigation
| Type:boolean
| Default value:false
- enables or disables navigation by keyboardpreviewAnimation
| Type:boolean
| Default value:true
- enables or disables image loading animationpreviewAutoPlay
| Type:boolean
| Default valuefalse
- enables or disables auto playpreviewAutoPlayInterval
| Type:number
| Default value:2000
- interval for auto play (ms)previewAutoPlayPauseOnHover
| Type:boolean
| Default value:false
- enables or disables pouse auto play on hoverpreviewInfinityMove
| Type:boolean
| Default value:false
- enables or disables infinity move by arrowspreviewZoom
| Type:boolean
| Default value:false
- enables or disables zoom in and zoom outpreviewZoomStep
| Type:number
| Default value:0.1
- step for zoom changepreviewZoomMax
| Type:number
| Default value:2
- max value for zoompreviewZoomMin
| Type:number
| Default value:0.5
- min value for zoompreviewRotate
| Type:boolean
| Default value:false
- enables or disables rotate buttonspreviewDownload
| Type:boolean
| Default value:false
- enables or disables downoad buttonpreviewBullets
| Type:boolean
| Default value:false
- enables or disables navigation bulletsccpPreviewImageAsLink
| Type:boolean
| Default value:false
- enables or disables links on preview imagearrowPrevIcon
| Type:string
| Default value:'fa fa-arrow-circle-left'
- icon for prev arrowarrowNextIcon
| Type:string
| Default value:'fa fa-arrow-circle-right'
- icon for next arrowcloseIcon
| Type:string
| Default value:'fa fa-times-circle'
- icon for close buttonfullscreenIcon
| Type:string
| Default value:'fa fa-arrows-alt'
- icon for fullscreen buttonspinnerIcon
| Type:string
| Default value:'fa fa-spinner fa-pulse fa-3x fa-fw'
- icon for spinnerzoomInIcon
| Type:string
| Default value:'fa fa-search-plus'
- icon for zoom inzoomOutIcon
| Type:string
| Default value:'fa fa-search-minus'
- icon for zoom outrotateLeftIcon
| Type:string
| Default value:'fa fa-undo'
- icon for rotate leftrotateRightIcon
| Type:string
| Default value:'fa fa-repeat'
- icon for rotate rightdownloadIcon
| Type:string
| Default value:'fa fa-arrow-circle-down'
- icon for downloadactions
| Type:NgxGalleryAction[]
| Default value:[]
- Array of new custom actions that will be added to the left of the current close/zoom/fullscreen icons
NgxGalleryImage
small
| Type:string | SafeResourceUrl
- url used in thumbnailsmedium
| Type:string | SafeResourceUrl
- url used in imagebig
| Type:string | SafeResourceUrl
- url used in previewdescription
| Type:string
- description used in previewurl
| Type:string
- url used in linklabel
| Type:string
- label used for aria-label when thumbnail is a link
NgxGalleryAnimation
Fade
(default)Slide
Rotate
Zoom
NgxGalleryImageSize
Cover
(default)Contain
NgxGalleryLayout
Top
Bottom
(default)
NgxGalleryOrder
Column
(default)Row
Page
Examples for
NgxGalleryAction
icon
| Type:string
- icon for custom actiondisabled
| Type:boolean
| Default value:false
- if the icon should be disabledtitleText
| Type:string
| Default value:''
- text to set the title attribute toonClick
| Type:(event: Event, index: number) => void
- Output function to call when custom action icon is clicked
Events
change
- triggered on image changeimagesReady
- triggered when images length > 0previewOpen
- triggered on preview openpreviewClose
- triggered on preview closepreviewChange
- triggered on preview image change
Methods
show(index: number): void
- shows image at indexshowNext(): void
- shows next imageshowPrev(): void
- shows prev imagecanShowNext(): boolean
- returns true if there is next imagecanShowPrev(): boolean
- returns true if there is prev imageopenPreview(index: number): void
- opens preview at indexmoveThumbnailsLeft(): void
- moves thumbnails to leftmoveThumbnailsRight(): void
- moves thumbnails to rightcanMoveThumbnailsLeft(): boolean
- returns true if you can move thumbnails to leftcanMoveThumbnailsRight(): boolean
- returns true if you can move thumbnails to right
Usage
// app.module.ts
import { NgxGalleryModule } from 'ngx-gallery';
...
@NgModule({
imports: [
...
NgxGalleryModule
...
],
...
})
export class AppModule { }
// app.component.ts
import { Component, OnInit } from '@angular/core';
import { NgxGalleryOptions, NgxGalleryImage, NgxGalleryAnimation } from 'ngx-gallery';
...
@Component({
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
galleryOptions: NgxGalleryOptions[];
galleryImages: NgxGalleryImage[];
ngOnInit(): void {
this.galleryOptions = [
{
width: '600px',
height: '400px',
thumbnailsColumns: 4,
imageAnimation: NgxGalleryAnimation.Slide
},
// max-width 800
{
breakpoint: 800,
width: '100%',
height: '600px',
imagePercent: 80,
thumbnailsPercent: 20,
thumbnailsMargin: 20,
thumbnailMargin: 20
},
// max-width 400
{
breakpoint: 400,
preview: false
}
];
this.galleryImages = [
{
small: 'assets/1-small.jpg',
medium: 'assets/1-medium.jpg',
big: 'assets/1-big.jpg'
},
{
small: 'assets/2-small.jpg',
medium: 'assets/2-medium.jpg',
big: 'assets/2-big.jpg'
},
{
small: 'assets/3-small.jpg',
medium: 'assets/3-medium.jpg',
big: 'assets/3-big.jpg'
}
];
}
}
// app.component.html
<ngx-gallery [options]="galleryOptions" [images]="galleryImages"></ngx-gallery>
Styling
- Active thumbnail
::ng-deep .ngx-gallery-thumbnail.ngx-gallery-active {
/* your styles */
}
- Arrow
ngx-gallery ::ng-deep .ngx-gallery-arrow {
/* your styles */
}
- Arrow in particular element
ngx-gallery ::ng-deep ngx-gallery-image .ngx-gallery-arrow {
/* your styles */
}
ngx-gallery ::ng-deep ngx-gallery-thumbnails .ngx-gallery-arrow {
/* your styles */
}
ngx-gallery ::ng-deep ngx-gallery-preview .ngx-gallery-arrow {
/* your styles */
}
Donate
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago