- Notifications
You must be signed in to change notification settings - Fork18
Lightbox2 port to use with angular2
License
themyth92/angular2-lightbox
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Alighbox2 implementation port to use with Angular2 without the need for jQuery
This module works with angular 2.x and 4.xdemo
For angular >= 5 support. Please usengx-lightbox.
npm install --save angular2-lightbox
Update yoursystem.config.js
{map:{'angular2-lightbox':'node_modules/angular2-lightbox'},packages:{'angular2-lightbox':{main:'./index.js',defaultExtension:'js'}}}
Include modified version oflightbox.css
in yourindex.html
<linkrel="stylesheet"href="./node_modules/angular2-lightbox/lightbox.css">
ImportLightboxModule
fromangular2-lightbox
import{LightboxModule}from'angular2-lightbox';@NgModule({imports:[LightboxModule]})
- Markup
<div*ngFor="let image of _albums; let i=index"><img[src]="image.thumb"(click)="open(i)"/></div>
- Component method
import{Lightbox}from'angular2-lightbox';exportclassAppComponent{private_album:Array=[];constructor(private_lightbox:Lightbox){for(leti=1;i<=4;i++){constsrc='demo/img/image'+i+'.jpg';constcaption='Image '+i+' caption here';constthumb='demo/img/image'+i+'-thumb.jpg';constalbum={src:src,caption:caption,thumb:thumb};this._albums.push(album);}}open(index:number):void{// open lightboxthis._lightbox.open(this._albums,index);}}
Eachobject
ofalbum
array inside your component may contains 3 properties :
Properties | Requirement | Description |
---|---|---|
src | Required | The source image to your thumbnail that you want to with use lightbox when user click onthumbnail image |
caption | Optional | Your caption corresponding with your image |
thumb | Optional | Source of your thumbnail. It is being used inside your component markup so this properties depends on your naming. |
- Listen to lightbox event
You can listen to 3 events, which are eitherCHANGE_PAGE,CLOSE orOPEN.
import{LightboxEvent,LIGHTBOX_EVENT}from'angular2-lightbox';import{Subscription}from'rxjs/Subscription';exportclassAppComponent{private_subscription:Subscription;constructor(private_lightboxEvent:LightboxEvent){}open(index:number):void{// register your subscription and callback whe open lightbox is firedthis._subscription=this._lightboxEvent.lightboxEvent$.subscribe(event=>this._onReceivedEvent(event));}private_onReceivedEvent(event:any):void{// remember to unsubscribe the event when lightbox is closedif(event.id===LIGHTBOX_EVENT.CLOSE){// event CLOSED is firedthis._subscription.unsubscribe();}if(event.id===LIGHTBOX_EVENT.OPEN){// event OPEN is fired}if(event.id===LIGHTBOX_EVENT.CHANGE_PAGE){// event change page is firedconsole.log(event.data);// -> image index that lightbox is switched to}}}
Available options based on lightbox2 options
Properties | Default | Description |
---|---|---|
fadeDuration | 0.7 seconds | duration starting when thesrc image isloaded tofully appear onto screen. |
resizeDuration | 0.5 seconds | duration starting when Lightbox containerchange its dimension from adefault/previous image to thecurrent image when thecurrent image isloaded. |
fitImageInViewPort | true | Determine whether lightbox will use the natural imagewidth/height or change the imagewidth/height to fit the view of current window. Change this option totrue to prevent problem when image too big compare to browser windows. |
positionFromTop | 20 px | The position of lightbox from the top of window browser |
showImageNumberLabel | false | Determine whether to show the image number to user. The default text shown isImage IMAGE_NUMBER of ALBUM_LENGTH |
alwaysShowNavOnTouchDevices | false | Determine whether to showleft/right arrow to user on Touch devices. |
wrapAround | false | Determine whether to move to the start of the album when user reaches the end of album and vice versa. Set it totrue to enable this feature. |
disableKeyboardNav | false | Determine whether to disable navigation using keyboard event. |
disableScrolling | false | Iftrue, prevent the page from scrolling while Lightbox is open. This works by settings overflow hidden on the body. |
centerVertically | false | Iftrue, images will be centered vertically to the screen. |
NOTE: You can either override default config or during a specific opening window
- Override default config
import{LightboxConfig}from'angular2-lightbox';exportclassAppComponent{constructor(private_lighboxConfig:LightboxConfig){// override default config_lighboxConfig.fadeDuration=1;}}
- Set config in a specific opening window
import{LightboxConfig,Lightbox}from'angular2-lightbox';exportclassAppComponent{constructor(private_lighboxConfig:LightboxConfig,private_lightbox:Lightbox){}open(index:number){// override the default config on second parameterthis._lightbox.open(this._albums,index,{wrapAround:true,showImageNumberLabel:true});}}
MIT
Buy me a beer if you like
BTC: 1MFx5waJ7Sitn961DaXe3mQXrb7pEoSJct
ETH: 0x2211F3d683eB1C2d753aD21D9Bd9110729C80B72
NEO: ARrUrnbq1ogfsoabvCgJ5SHgknhzyUmtuS
About
Lightbox2 port to use with angular2
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors5
Uh oh!
There was an error while loading.Please reload this page.