照片瀏覽器 Svelte 組件

照片瀏覽器是一個照片瀏覽器組件,用於顯示照片 / 影像的集合。照片可以縮放和平移(可選)。

照片瀏覽器 Svelte 組件代表 Framework7 的 照片瀏覽器 組件。

Photo Browser Svelte 元件不會呈現任何輸出。它可用於建立 JS Photo Browser 實例,並在 Svelte 元件中控制它。

Photo Browser 元件

包含下列元件

Photo Browser 屬性

你可以傳遞所有參數到單一 `params` 屬性,或使用個別屬性來指定每個參數,以透過元件屬性來指定它們

屬性類型預設值說明
<PhotoBrowser> 屬性
init布林值true初始化 Photo Browser
params物件包含 Photo Browser 參數 的物件
photos陣列[]包含照片 URL 的陣列,或包含「url」(或「html」)和「caption」屬性的物件陣列。
thumbs陣列[]陣列
包含縮圖影像 URL 的陣列。如果未指定或陣列為空,將不會呈現縮圖url字串photos/
將設定為目前路由的 Photo Browser 模組 URL布林值routableModalsfalse
會將開啟的 Photo Browser 加入路由記錄,這讓你可以透過在路由記錄中返回來關閉 Photo Browser,並將目前路由設定為 Photo Browser 模組swiper物件
swiper: {
  initialSlide: 0,
  spaceBetween: 20,
  speed: 300,
  loop: false,
  preloadImages: true,
  keyboard: {
    enabled: true,
  },
  navigation: {
    nextEl: '.photo-browser-next',
    prevEl: '.photo-browser-prev',
  },
  zoom: {
    enabled: true,
    maxRatio: 3,
    minRatio: 1,
  },
  lazy: {
    enabled: true,
  },
},
包含 Swiper 參數的物件。預設值為布林值truevirtualSlides
啟用時,Swiper 將使用虛擬投影片布林值truecloseByBackdropClick
啟用時,Photo Browser 快顯視窗會在點選背景時關閉布林值trueexposition
點選 Photo Browser 時啟用或停用說明模式。布林值routableModalsexpositionHideCaptions
如果你也想在說明模式中隱藏說明文字,請設定為 true布林值trueswipeToClose
啟用此參數時,你可以透過向上/向下滑動來關閉 Photo Browserurltypestandalone
定義 Photo Browser 應如何開啟。可以是 `standalone`(會以自訂轉場效果開啟為疊加層)、`popup`(會開啟為快顯視窗)、`page`(會注入到檢視中,並載入為新頁面)。urlthemelight
captionsThemeurl圖說色彩主題,也可以是 darklight。預設值等於「主題」參數
navbar布林值true設定為 false 可移除 Photo Browser 的導覽列
toolbar布林值true設定為 false 可移除 Photo Browser 的工具列
pageBackLinkTexturl返回Photo Browser 導覽列中返回連結的文字
popupCloseLinkTexturl關閉在彈出視窗或獨立模式中開啟時,Photo Browser 導覽列中關閉連結的文字
navbarShowCount布林值未定義定義是否在導覽列標題中顯示「5 中的 3」文字。如果未指定(未定義),則在有超過 1 個項目時顯示此文字
navbarOfTexturl照片計數器中「的」文字:「5 中的 3」
iconsColorurl預設色彩之一

Photo Browser 事件

事件說明
<PhotoBrowser> 事件
photoBrowserOpenPhoto Browser 開啟時觸發事件。
photoBrowserOpenedPhoto Browser 完成開啟動畫後觸發事件
photoBrowserClosePhoto Browser 關閉時觸發事件。
photoBrowserClosedPhoto Browser 完成關閉動畫後觸發事件
photoBrowserSwipeToClose使用者以向上/向下滑動關閉 Photo Browser 時觸發此事件。

Photo Browser 方法

可以使用以下 Photo Browser 元件方法(例如透過 bind:this 存取它)

<PhotoBrowser> 方法
.open(index)在索引號碼等於「index」參數的照片上開啟 Photo Browser。如果未指定「index」參數,則會在最後一次關閉的照片上開啟。
.close()關閉 Photo Browser
.expositionToggle()切換曝光模式
.expositionEnable()啟用曝光模式
.expositionDisable()停用曝光模式

存取 Photo Browser 實例

您可以透過呼叫元件的 .instance() 方法存取已初始化的 Photo Browser 實例。例如

<PhotoBrowser bind:this={component}>...</PhotoBrowser>

<script>
  let component;

  // to get instance in some method
  component.instance()
</script>

範例

photo-browser.svelte
<script>
  import { Navbar, Page, PhotoBrowser, Block, Button } from 'framework7-svelte';

  let standalone;
  let popup;
  let page;

  let standaloneDark;
  let popupDark;
  let pageDark;

  const photos = [
    {
      url: 'img/beach.jpg',
      caption: 'Amazing beach in Goa, India',
    },
    'http://placekitten.com/1024/1024',
    'img/lock.jpg',
    {
      url: 'img/monkey.jpg',
      caption: 'I met this monkey in Chinese mountains',
    },
    {
      url: 'img/mountains.jpg',
      caption: 'Beautiful mountains in Zhangjiajie, China',
    },
  ];

  const thumbs = [
    'img/beach.jpg',
    'http://placekitten.com/1024/1024',
    'img/lock.jpg',
    'img/monkey.jpg',
    'img/mountains.jpg',
  ];
</script>

<Page>
  <Navbar title="Photo Browser" />
  <Block strongIos outlineIos>
    <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>
    <ul>
      <li>Swiper between photos</li>
      <li>Multi-gestures support for zooming</li>
      <li>Toggle zoom by double tap on photo</li>
      <li>Single click on photo to toggle Exposition mode</li>
    </ul>
  </Block>
  <Block strongIos outlineIos>
    <p>
      Photo Browser could be opened in a three ways - as a Standalone component (Popup
      modification), in Popup, and as separate Page:
    </p>
    <div class="grid grid-cols-3 grid-gap">
      <div>
        <PhotoBrowser {photos} {thumbs} bind:this={standalone} />
        <Button fill onClick={() => standalone.open()}>Standalone</Button>
      </div>
      <div>
        <PhotoBrowser {photos} {thumbs} type="popup" bind:this={popup} />
        <Button fill onClick={() => popup.open()}>Popup</Button>
      </div>
      <div>
        <PhotoBrowser {photos} {thumbs} type="page" pageBackLinkText="Back" bind:this={page} />
        <Button fill onClick={() => page.open()}>Page</Button>
      </div>
    </div>
  </Block>
  <Block strongIos outlineIos>
    <p>
      Photo Browser supports 2 default themes - default Light (like in previous examples) and Dark
      theme. Here is a Dark theme examples:
    </p>
    <div class="grid grid-cols-3 grid-gap">
      <div>
        <PhotoBrowser {photos} {thumbs} theme="dark" bind:this={standaloneDark} />
        <Button fill onClick={() => standaloneDark.open()}>Standalone</Button>
      </div>
      <div>
        <PhotoBrowser {photos} {thumbs} theme="dark" type="popup" bind:this={popupDark} />
        <Button fill onClick={() => popupDark.open()}>Popup</Button>
      </div>
      <div>
        <PhotoBrowser
          {photos}
          {thumbs}
          theme="dark"
          type="page"
          pageBackLinkText="Back"
          bind:this={pageDark}
        />
        <Button fill onClick={() => pageDark.open()}>Page</Button>
      </div>
    </div>
  </Block>
</Page>