Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Lightbox2 port to use with angular2

License

NotificationsYou must be signed in to change notification settings

themyth92/angular2-lightbox

Repository files navigation

Build Status

Angular2 Lightbox

Alighbox2 implementation port to use with Angular2 without the need for jQuery

This module works with angular 2.x and 4.xdemo

NOTICE:

For angular >= 5 support. Please usengx-lightbox.

Installation

npm install --save angular2-lightbox

Update yoursystem.config.js

{map:{'angular2-lightbox':'node_modules/angular2-lightbox'},packages:{'angular2-lightbox':{main:'./index.js',defaultExtension:'js'}}}

Usage

CSS

Include modified version oflightbox.css in yourindex.html

<linkrel="stylesheet"href="./node_modules/angular2-lightbox/lightbox.css">

Module:

ImportLightboxModule fromangular2-lightbox

import{LightboxModule}from'angular2-lightbox';@NgModule({imports:[LightboxModule]})

Component

  1. Markup
<div*ngFor="let image of _albums; let i=index"><img[src]="image.thumb"(click)="open(i)"/></div>
  1. 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 :

PropertiesRequirementDescription
srcRequiredThe source image to your thumbnail that you want to with use lightbox when user click onthumbnail image
captionOptionalYour caption corresponding with your image
thumbOptionalSource of your thumbnail. It is being used inside your component markup so this properties depends on your naming.
  1. 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}}}

Lightbox options

Available options based on lightbox2 options

PropertiesDefaultDescription
fadeDuration0.7 secondsduration starting when thesrc image isloaded tofully appear onto screen.
resizeDuration0.5 secondsduration starting when Lightbox containerchange its dimension from adefault/previous image to thecurrent image when thecurrent image isloaded.
fitImageInViewPorttrueDetermine 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.
positionFromTop20 pxThe position of lightbox from the top of window browser
showImageNumberLabelfalseDetermine whether to show the image number to user. The default text shown isImage IMAGE_NUMBER of ALBUM_LENGTH
alwaysShowNavOnTouchDevicesfalseDetermine whether to showleft/right arrow to user on Touch devices.
wrapAroundfalseDetermine 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.
disableKeyboardNavfalseDetermine whether to disable navigation using keyboard event.
disableScrollingfalseIftrue, prevent the page from scrolling while Lightbox is open. This works by settings overflow hidden on the body.
centerVerticallyfalseIftrue, images will be centered vertically to the screen.

NOTE: You can either override default config or during a specific opening window

  1. Override default config
import{LightboxConfig}from'angular2-lightbox';exportclassAppComponent{constructor(private_lighboxConfig:LightboxConfig){// override default config_lighboxConfig.fadeDuration=1;}}
  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});}}

License

MIT

Donation

Buy me a beer if you like

BTC: 1MFx5waJ7Sitn961DaXe3mQXrb7pEoSJct

ETH: 0x2211F3d683eB1C2d753aD21D9Bd9110729C80B72

NEO: ARrUrnbq1ogfsoabvCgJ5SHgknhzyUmtuS

About

Lightbox2 port to use with angular2

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors5


[8]ページ先頭

©2009-2025 Movatter.jp