All Projects → themyth92 → Ngx Lightbox

themyth92 / Ngx Lightbox

Licence: mit
Lightbox2 use with angular >= 5

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Ngx Lightbox

Angular Infinite List
A short and powerful infinite scroll list library for angular, with zero dependencies
Stars: ✭ 77 (-8.33%)
Mutual labels:  angular5, angular6
Ngx Smart Modal
Modal/Dialog component crafted for Angular
Stars: ✭ 256 (+204.76%)
Mutual labels:  angular5, angular6
mean-stack
MEAN stack Mongoose, Express, Angular6, Node
Stars: ✭ 22 (-73.81%)
Mutual labels:  angular5, angular6
ngx-konami
A simple directive to add easter eggs in your Angular application 👾
Stars: ✭ 34 (-59.52%)
Mutual labels:  angular5, angular6
Angular Material App
基于最新Angular 9框架与Material 2技术的web中后台前端应用框架。
Stars: ✭ 509 (+505.95%)
Mutual labels:  angular5, angular6
angular-rollbar-source-maps
Angular 2+ implementation to upload sourcemaps to Rollbar
Stars: ✭ 17 (-79.76%)
Mutual labels:  angular5, angular6
ngx-img
No description or website provided.
Stars: ✭ 25 (-70.24%)
Mutual labels:  angular5, angular6
spring-websocket-angular6
Example for using Spring Websocket and Angular with Stomp Messaging
Stars: ✭ 18 (-78.57%)
Mutual labels:  angular5, angular6
Ngx Monaco Editor
Monaco Editor component for Angular 2 and Above
Stars: ✭ 347 (+313.1%)
Mutual labels:  angular5, angular6
Ng Http Loader
🍡 Smart angular HTTP interceptor - Intercepts automagically HTTP requests and shows a spinkit spinner / loader / progress bar
Stars: ✭ 327 (+289.29%)
Mutual labels:  angular5, angular6
ngx-print
🖨️ A plug n' play Angular (2++) library to print your stuff
Stars: ✭ 124 (+47.62%)
Mutual labels:  angular5, angular6
Nebular
💥 Customizable Angular UI Library based on Eva Design System 🌚✨Dark Mode
Stars: ✭ 7,368 (+8671.43%)
Mutual labels:  angular5, angular6
ng-pdf-highlighter
PDF annotation with angular7
Stars: ✭ 15 (-82.14%)
Mutual labels:  angular5, angular6
ngx-image-editor
Awesome image editor for Angular 6
Stars: ✭ 74 (-11.9%)
Mutual labels:  angular5, angular6
ng-toggle
Bootstrap-styled Angular Toggle Component
Stars: ✭ 14 (-83.33%)
Mutual labels:  angular5, angular6
angular-progress-bar
This component allow you to easy incorporate progress-bar to angular/ionic project, providing binding and color options
Stars: ✭ 26 (-69.05%)
Mutual labels:  angular5, angular6
angularx-qrcode-sample-app
Angular5/6/7/8/9/10+ sample apps with working implementations of angularx-qrcode
Stars: ✭ 15 (-82.14%)
Mutual labels:  angular5, angular6
Angular-Reactive-Demo-Shop
Angular Demo Shop
Stars: ✭ 79 (-5.95%)
Mutual labels:  angular5, angular6
Angularx Qrcode
Angular4/5/6/7/8/9/10/11 QRCode generator component library for QR Codes (Quick Response) with AOT support based on node-qrcode
Stars: ✭ 281 (+234.52%)
Mutual labels:  angular5, angular6
Angular Froala Wysiwyg
Angular 4, 5, 6, 7, 8 and 9 plugin for Froala WYSIWYG HTML Rich Text Editor.
Stars: ✭ 696 (+728.57%)
Mutual labels:  angular5, angular6

Build Status

Ngx-Lightbox

A lightbox2 implementation port to use with new Angular without the need for jQuery

Version

Demo

Installation

npm install --save ngx-lightbox

Update your angular.json

{
  "styles": [
    "./node_modules/ngx-lightbox/lightbox.css",
    ...
  ],
}

Usage

Module:

Import LightboxModule from ngx-lightbox

import { LightboxModule } from 'ngx-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 'ngx-lightbox';

export class AppComponent {
  private _album: Array = [];
  constructor(private _lightbox: Lightbox) {
    for (let i = 1; i <= 4; i++) {
      const src = 'demo/img/image' + i + '.jpg';
      const caption = 'Image ' + i + ' caption here';
      const thumb = 'demo/img/image' + i + '-thumb.jpg';
      const album = {
         src: src,
         caption: caption,
         thumb: thumb
      };

      this._albums.push(album);
    }
  }

  open(index: number): void {
    // open lightbox
    this._lightbox.open(this._albums, index);
  }

  close(): void {
    // close lightbox programmatically
    this._lightbox.close();
  }
}

Each object of album 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 on thumbnail 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.
  1. Listen to lightbox event

You can listen to 3 events, which are either CHANGE_PAGE, CLOSE or OPEN.

import { LightboxEvent, LIGHTBOX_EVENT } from 'ngx-lightbox';
import { Subscription } from 'rxjs';

export class AppComponent {
  private _subscription: Subscription;
  constructor(private _lightboxEvent: LightboxEvent) {}
  open(index: number): void {
    // register your subscription and callback whe open lightbox is fired
    this._subscription = this._lightboxEvent.lightboxEvent$
      .subscribe(event => this._onReceivedEvent(event));
  }

  private _onReceivedEvent(event: any): void {
    // remember to unsubscribe the event when lightbox is closed
    if (event.id === LIGHTBOX_EVENT.CLOSE) {
      // event CLOSED is fired
      this._subscription.unsubscribe();
    }

    if (event.id === LIGHTBOX_EVENT.OPEN) {
      // event OPEN is fired
    }

    if (event.id === LIGHTBOX_EVENT.CHANGE_PAGE) {
      // event change page is fired
      console.log(event.data); // -> image index that lightbox is switched to
    }
  }
}

Lightbox options

Available options based on lightbox2 options

Properties Default Description
fadeDuration 0.7 seconds duration starting when the src image is loaded to fully appear onto screen.
resizeDuration 0.5 seconds duration starting when Lightbox container change its dimension from a default/previous image to the current image when the current image is loaded.
fitImageInViewPort true Determine whether lightbox will use the natural image width/height or change the image width/height to fit the view of current window. Change this option to true 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 is Image IMAGE_NUMBER of ALBUM_LENGTH
alwaysShowNavOnTouchDevices false Determine whether to show left/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 to true to enable this feature.
disableKeyboardNav false Determine whether to disable navigation using keyboard event.
disableScrolling false If true, prevent the page from scrolling while Lightbox is open. This works by settings overflow hidden on the body.
centerVertically false If true, images will be centered vertically to the screen.
albumLabel "Image %1 of %2" The text displayed below the caption when viewing an image set. The default text shows the current image number and the total number of images in the set.
enableTransition true Transition animation between images will be disabled if this flag set to false
showZoom false Zoom Buttons will be shown if this flag set to true
showRotate false Rotate Buttons will be shown if this flag set to true

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

  1. Override default config
import { LightboxConfig } from 'ngx-lightbox';

export class AppComponent {
  constructor(private _lightboxConfig: LightboxConfig) {
    // override default config
    _lightboxConfig.fadeDuration = 1;
  }
}
  1. Set config in a specific opening window
import { LightboxConfig, Lightbox } from 'ngx-lightbox';

export class AppComponent {
  constructor(private _lightboxConfig: LightboxConfig, private _lightbox: Lightbox) {}
  open(index: number) {
    // override the default config on second parameter
    this._lightbox.open(this._albums, index, { wrapAround: true, showImageNumberLabel: true });
  }
}

Angular Universal

For this to work with Angular Universal, you need to have a global window object defined in your server.js (the one in your Angular project derived from initiating an ssr project using Angular Universal) using any window npm lib like window or domino

Add the below to your server.js

global['window'] = window;

License

MIT

Donation

Buy me a beer if you like

BTC: 1MFx5waJ7Sitn961DaXe3mQXrb7pEoSJct

ETH: 0x2211F3d683eB1C2d753aD21D9Bd9110729C80B72

NEO: ARrUrnbq1ogfsoabvCgJ5SHgknhzyUmtuS

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].