DIV CSS 佈局教程網

jQuery插件實現大圖全屏圖片相冊
編輯:JQuery特效代碼     

這是一款大圖全屏的圖片相冊 jQuery 插件,基於 jQuery.album.js 封裝。它支持左右按鈕切換、點擊大圖自動播放,並提供豐富的可自定義參數。其中 viewMode 參數控制縮略圖顯示方式:0 表示無縮略圖、1 表示有縮略圖、2 表示全屏縮略圖,此外還支持圖片左右旋轉,具體參數可查閱 jQuery.album.js 源文件,整體效果相當出色。

頁面結構

相冊主體由大圖展示區、左右切換按鈕以及縮略圖列表組成,圖片數據則通過一個隱藏的 textarea 進行配置:

<div class="album-box" id="album">
  <div class="pre-btn" id="preBtn" title="上一張 "><i></i></div>
  <div class="next-btn" id="nextBtn" title="下一張 "><i></i></div>
  <div class="album-con">
    <div class="valin"> <i></i><img src="images/20140121161108.JPG" alt="" id="realImg" />
      <p class="pic-alt" id="txtDes"></p>
    </div>
    <div id="imgLoading"></div>
  </div>
  <div class="thum-box" id="thumBox">
    <div class="thum-wrap" id="thumWrap">
      <ul class="imglist fix" id="photoList">
      </ul>
    </div>
    <i class="thum-pre-btn" id="thumPreBtn" title="上一頁"></i> <i class="thum-next-btn" id="thumNextBtn" title="下一頁"></i>
  </div>
</div>

縮略圖數據與縮放函數

下面的 textarea 存放每張圖的縮略圖、大圖路徑與說明,scaleImage 函數則負責按比例縮放縮略圖:

<textarea class="dn" id="albumDataList">
  <li>
    <div> <img alt="JS相冊特效" src="images/tiny/20140121161108.JPG" onload="scaleImage(this,99,75)"></div>
    <p></p>
    <i class="dn">images/20140121161108.JPG</i>
    <i class="dn imgAlt"></i>
  </li>
</textarea>
<script type="text/javascript">
function scaleImage(o, w, h) {
  var img = new Image();
  img.src = o.src;
  if (img.width > 0 && img.height > 0) {
    if (img.width / img.height >= w / h) {
      if (img.width > w) {
        o.width = w;
        o.height = (img.height * w) / img.width;
      } else {
        o.width = img.width;
        o.height = img.height;
      }
    } else {
      if (img.height > h) {
        o.height = h;
        o.width = (img.width * h) / img.height;
      } else {
        o.width = img.width;
        o.height = img.height;
      }
    }
  }
}
</script>
<script type="text/javascript" src="js/jquery.album.js"></script>

以上就是本文分享給大家的實例代碼,希望對大家學習 jQuery 相冊插件有所幫助。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved