Photo Browser - 图1

Photo Browser Svelte Component

Photo Browser is an photo browser component to display collection of photos / images. Photos can be zoomed and panned (optional).

Photo Browser Svelte component represents Framework7’s Photo Browser component.

Photo Browser Svelte component doesn’t render any output. It can be used to create JS Photo Browser instance and control it inside of your Svelte component.

Photo Browser Component

There are following components included:

  • PhotoBrowser

Photo Browser Properties

You can pass all parameters in single params property or use separate props for each parameter to specify them via component properties:

PropTypeDefaultDescription
<PhotoBrowser> properties
initbooleantrueInitializes Photo Browser
paramsObjectObject with Photo Browser parameters
photosarray[]Array with URLs of photos or array of objects with “url” (or “html”) and “caption” properties.
urlstringphotos/Photo browser modal URL that will be set as a current route
routableModalsbooleantrueWill add opened photo browser to router history which gives ability to close photo browser by going back in router history and set current route to the photo browser modal
swiperobjectObject with Swiper parameters. By default equals to:
  1. swiper: {
  2. initialSlide: 0,
  3. spaceBetween: 20,
  4. speed: 300,
  5. loop: false,
  6. preloadImages: true,
  7. navigation: {
  8. nextEl: ‘.photo-browser-next’,
  9. prevEl: ‘.photo-browser-prev’,
  10. },
  11. zoom: {
  12. enabled: true,
  13. maxRatio: 3,
  14. minRatio: 1,
  15. },
  16. lazy: {
  17. enabled: true,
  18. },
  19. },
virtualSlidesbooleantrueWhen enabled then Swiper will use Virtual Slides
expositionbooleantrueEnable disable exposition mode when clicking on Photo Browser.
expositionHideCaptionsbooleanfalseSet to true if you also want to hide captions in exposition mode
swipeToClosebooleantrueYou can close Photo Browser with swipe up/down when this parameter is enabled
typestringstandaloneDefine how Photo Browser should be opened. Could be standalone (will be opened as an overlay with custom transition effect), popup (will be opened as popup), page (will be injected to View and loaded as a new page).
themestringlightPhoto Browser color theme, could be light or dark
captionsThemestringCaptions color theme, could be also dark or light. By default, equal to “theme” parameter
navbarbooleantrueSet to false to remove Photo Browser’s Navbar
toolbarbooleantrueSet to false to remove Photo Browser’s Toolbar
pageBackLinkTextstringBackText on back link in Photo Browser’s navbar
popupCloseLinkTextstringCloseText on close link in Photo Browser’s navbar when opened in Popup or as Standalone
navbarShowCountbooleanundefinedDefines should it display “3 of 5” text in navbar title or not. If not specified (undefined) then it will show this text if there is more than 1 item
navbarOfTextstringofText of “of” in photos counter: “3 of 5”
iconsColorstringOne of the default colors

Photo Browser Events

EventDescription
<PhotoBrowser> events
photoBrowserOpenEvent will be triggered on Photo Browser open.
photoBrowserOpenedEvent will be triggered after Photo Browser completes its opening animation
photoBrowserCloseEvent will be triggered on Photo Browser close.
photoBrowserClosedEvent will be triggered after Photo Browser completes its closing animation
photoBrowserSwipeToCloseThis event will be triggered when user close Photo Browser with swipe up/down.

Photo Browser Methods

The following Photo Browser components methods are available (e.g. by accesing it via $refs):

<PhotoBrowser> methods
.open(index);Open Photo Browser on photo with index number equal to “index” parameter. If “index” parameter is not specified, it will be opened on last closed photo.
.close();Close Photo Browser
.expositionToggle();Toggle exposition mode
.expositionEnable();Enable exposition mode
.expositionDisable();Disable exposition mode

Access To Photo Browser Instance

You can access Photo Browser initialized instance by calling .instance() component’s method. For example:

  1. <PhotoBrowser bind:this={component}>...</PhotoBrowser>
  2. <script>
  3. let component;
  4. // to get instance in some method
  5. component.instance()
  6. </script>

Examples

  1. <Page>
  2. <Navbar title="Photo Browser" />
  3. <Block strong>
  4. <p>Photo Browser is a standalone and highly configurable component that allows to open window with photo viewer and navigation elements with the following features:</p>
  5. <ul>
  6. <li>Swiper between photos</li>
  7. <li>Multi-gestures support for zooming</li>
  8. <li>Toggle zoom by double tap on photo</li>
  9. <li>Single click on photo to toggle Exposition mode</li>
  10. </ul>
  11. </Block>
  12. <Block strong>
  13. <p>Photo Browser could be opened in a three ways - as a Standalone component (Popup modification), in Popup, and as separate Page:</p>
  14. <Row>
  15. <Col>
  16. <PhotoBrowser photos={photos} bind:this={standalone} />
  17. <Button fill raised onClick={() => standalone.open()}>Standalone</Button>
  18. </Col>
  19. <Col>
  20. <PhotoBrowser photos={photos} type="popup" bind:this={popup} />
  21. <Button fill raised onClick={() => popup.open()}>Popup</Button>
  22. </Col>
  23. <Col>
  24. <PhotoBrowser photos={photos} type="page" pageBackLinkText="Back" bind:this={page} />
  25. <Button fill raised onClick={() => page.open()}>Page</Button>
  26. </Col>
  27. </Row>
  28. </Block>
  29. <Block strong>
  30. <p>Photo Browser suppots 2 default themes - default Light (like in previous examples) and Dark theme. Here is a Dark theme examples:</p>
  31. <Row>
  32. <Col>
  33. <PhotoBrowser photos={photos} theme="dark" bind:this={standaloneDark} />
  34. <Button fill raised onClick={() => standaloneDark.open()}>Standalone</Button>
  35. </Col>
  36. <Col>
  37. <PhotoBrowser photos={photos} theme="dark" type="popup" bind:this={popupDark} />
  38. <Button fill raised onClick={() => popupDark.open()}>Popup</Button>
  39. </Col>
  40. <Col>
  41. <PhotoBrowser photos={photos} theme="dark" type="page" pageBackLinkText="Back" bind:this={pageDark} />
  42. <Button fill raised onClick={() => pageDark.open()}>Page</Button>
  43. </Col>
  44. </Row>
  45. </Block>
  46. </Page>
  47. <script>
  48. import {Page, Navbar, Block, Row, Col, PhotoBrowser, Button} from 'framework7-svelte';
  49. let standalone;
  50. let popup;
  51. let page;
  52. let standaloneDark;
  53. let popupDark;
  54. let pageDark;
  55. let photos = [
  56. 'https://placekitten.com/800/800',
  57. 'https://placekitten.com/1024/1024',
  58. ];
  59. </script>

← Panel / Side Panels

Popover →