LightboxLightBox is a modal overlay component to display images, videos, inline html content and iframes.

Lightbox - 图1

Documentation

Import

  1. import {LightboxModule} from 'primeng/lightbox';
  2.  

Getting Started

Lightbox has two modes; image and custom content defined using type property. In image mode a collection of images are required to display where an image object in the collection defines the source of the original image, thumbnail image and the title.

  1. <p-lightbox [images]="images"></p-lightbox>
  2.  
  1. export class LightboxDemo {
  2. images: any[];
  3. constructor() {
  4. this.images = [];
  5. this.images.push({source:'assets/showcase/images/demo/sopranos/sopranos1.jpg', thumbnail: 'assets/showcase/images/demo/sopranos/sopranos1_small.jpg', title:'Sopranos 1'});
  6. this.images.push({source:'assets/showcase/images/demo/sopranos/sopranos2.jpg', thumbnail: 'assets/showcase/images/demo/sopranos/sopranos2_small.jpg', title:'Sopranos 2'});
  7. this.images.push({source:'assets/showcase/images/demo/sopranos/sopranos3.jpg', thumbnail: 'assets/showcase/images/demo/sopranos/sopranos3_small.jpg', title:'Sopranos 3'});
  8. this.images.push({source:'assets/showcase/images/demo/sopranos/sopranos4.jpg', thumbnail: 'assets/showcase/images/demo/sopranos/sopranos4_small.jpg', title:'Sopranos 4'});
  9. }
  10. }
  11.  

Content mode is enabled by setting type property to "content", providing an anchor to open the lightbox and content to display inside lightbox.

  1. <p-lightbox type="content">
  2. <a class="group" href="#">
  3. Watch Video
  4. </a>
  5. <iframe width="560" height="315" src="https://www.youtube.com/embed/9bZkp7q19f0" frameborder="0" allowfullscreen></iframe>
  6. </p-lightbox>
  7.  

Effects

The easing function to use between image transitions is "ease-out" by default and this can be customized using easing property. See here for possible alternative values. Duration of the effect can be changed using effectDuration option.

  1. <p-lightbox [images]="images" easing="ease-in" effectDuration="1500ms"></p-lightbox>
  2.  

Properties

NameTypeDefaultDescription
imagesarraynullAn array of images to display.
typestringimageType of the lightbox, valid values are "image" and "content".
stylestringnullInline style of the component.
styleClassstringnullStyle class of the component.
easingstringease-outEasing to use for transition between images.
effectDurationstring500msDuration of the transition between the images.
baseZIndexnumber0Base zIndex value to use in layering.
autoZIndexbooleantrueWhether to automatically manage layering.

Styling

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
ui-lightboxContainer element
ui-lightbox-contentContent element.
ui-lightbox-nav-rightElement to navigate to next image.
ui-lightbox-nav-leftElement to navigate to previous image.
ui-lightbox-captionCaption element.
ui-lightbox-caption-textText of caption.
ui-lightbox-closeClose icon.

Dependencies

None.

Source

View on GitHub

  1. <h3 class="first">Basic</h3>
  2. <p-lightbox [images]="images"></p-lightbox>
  3. <h3>Content</h3>
  4. <p-lightbox type="content">
  5. <a class="group" href="#">
  6. Watch Video
  7. </a>
  8. <iframe width="560" height="315" src="https://www.youtube.com/embed/9bZkp7q19f0" frameborder="0" allowfullscreen></iframe>
  9. </p-lightbox>
  10.  
  1. export class LightboxDemo {
  2. images: any[];
  3. constructor() {
  4. this.images = [];
  5. this.images.push({source:'assets/showcase/images/demo/sopranos/sopranos1.jpg', thumbnail: 'assets/showcase/images/demo/sopranos/sopranos1_small.jpg', title:'Sopranos 1'});
  6. this.images.push({source:'assets/showcase/images/demo/sopranos/sopranos2.jpg', thumbnail: 'assets/showcase/images/demo/sopranos/sopranos2_small.jpg', title:'Sopranos 2'});
  7. this.images.push({source:'assets/showcase/images/demo/sopranos/sopranos3.jpg', thumbnail: 'assets/showcase/images/demo/sopranos/sopranos3_small.jpg', title:'Sopranos 3'});
  8. this.images.push({source:'assets/showcase/images/demo/sopranos/sopranos4.jpg', thumbnail: 'assets/showcase/images/demo/sopranos/sopranos4_small.jpg', title:'Sopranos 4'});
  9. }
  10. }
  11.