Orbit.js 是 ZURB Foundation 框架內建的響應式圖片輪播插件,支援折疊/立體切換效果。本文詳細說明整合步驟、配置選項、常見問題與現代替代方案。
project/
├── css/
│ ├── chuxz.css # Orbit 核心樣式
│ └── orbit.css # 可選:主題樣式
├── js/
│ ├── jquery.min.js # jQuery 1.7+ (必須)
│ ├── jq.orbit.js # Orbit 核心邏輯
│ └── orbit.js # 初始化配置
└── images/
├── 1.jpg ~ 5.jpg # 輪播圖片
└── loading.gif # 載入指示器
<div class="orbit-wrapper">
<div id="featured" class="orbit" role="region" aria-label="圖片輪播">
<a href="https://example.com/1">
<img src="images/1.jpg" width="185" alt="《Just Married》" title="《Just Married》">
</a>
<a href="https://example.com/2">
<img src="images/2.jpg" width="185" alt="《佩加索斯》" title="《佩加索斯》">
</a>
<a href="https://example.com/3">
<img src="images/3.jpg" width="185" alt="《太廟的一場偶遇》" title="《太廟的一場偶遇》">
</a>
<a href="https://example.com/4">
<img src="images/4.jpg" width="185" alt="《為愛癡狂》" title="《為愛癡狂》">
</a>
<a href="https://example.com/5">
<img src="images/5.jpg" width="185" alt="《游走,在北京的每一條街》" title="《游走,在北京的每一條街》">
</a>
</div>
</div>
<!-- 載入腳本 (建議置底) -->
<script src="js/jquery.min.js"></script>
<script src="js/jq.orbit.js"></script>
<script src="js/orbit.js"></script>
$(window).on('load', function() {
$('#featured').orbit({
// 基本設定
animation: 'fade', // fade | horizontal-slide | vertical-slide | horizontal-push
animationSpeed: 800, // 動畫持續時間 (ms)
timerSpeed: 4000, // 自動播放間隔 (ms)
pauseOnHover: true, // 滑鼠懸停暫停
startClockOnMouseOut: true,
startClockOnMouseOutAfter: 1000,
// 導航設定
navigationArrows: true, // 顯示左右箭頭
nextArrowText: '>',
prevArrowText: '<',
bulletNavigation: true, // 圓點導航
bulletThumbs: false, // 縮圖導航
bulletThumbLocation: '',
// 進階設定
directionalNav: true, // 方向鍵導航
captions: true, // 顯示標題 (img title/alt)
captionAnimation: 'fade', // slide | fade
captionAnimationSpeed: 600,
// 回呼函式
beforeSlideChange: function() {},
afterSlideChange: function() {},
afterLoadComplete: function() {}
});
});
/* CSS 預留空間 */
.orbit-wrapper {
position: relative;
width: 100%;
/* 使用 aspect-ratio 現代寫法 */
aspect-ratio: 185 / 185; /* 根據實際圖片比例調整 */
overflow: hidden;
}
/* 或舊版相容寫法 */
.orbit-wrapper::before {
content: '';
display: block;
padding-top: 100%; /* 高度 = 寬度 * 100% */
}
/* CSS 讓圖片自適應容器 */
.orbit img {
max-width: 100%;
height: auto;
display: block;
}
/* 進階:picture 元素 + srcset (現代瀏覽器) */
// Orbit 產生的標記需補強:
// 1. 容器加 role="region" aria-label
// 2. 箭頭按鈕加 aria-label="上一張"/"下一張"
// 3. 圓點按鈕加 role="tablist" + aria-label
// 4. 滑鼠/鍵盤焦點時暫停自動播放
// 5. prefers-reduced-motion 媒體查詢停用動畫
@media (prefers-reduced-motion: reduce) {
.orbit * {
animation: none !important;
transition: none !important;
}
}
Orbit.js 隨 Foundation 6 移除,不再維護。新專案強烈建議使用:
| 插件 | 特色 | 體積 | 相依性 |
|---|---|---|---|
| Swiper | 功能最完整、觸控佳、模組化、SSR支援 | ~40KB | 無 |
| Flickity | 物理拖拽感、無障礙好、選項豐富 | ~25KB | 無 |
| Splide | 輕量、TypeScript、無障礙優先、可擴展 | ~22KB | 無 |
| Glide.js | 極輕量、ES模組、無相依 | ~13KB | 無 |
| Tiny Slider | 無相依、IE10+、CSS優先 | ~10KB | 無 |
import Swiper from 'swiper';
import 'swiper/css';
import 'swiper/css/pagination';
import 'swiper/css/navigation';
new Swiper('.swiper', {
loop: true,
autoplay: { delay: 4000, disableOnInteraction: false },
pagination: { el: '.swiper-pagination', clickable: true },
navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' },
effect: 'fade', // 或 'slide', 'cube', 'coverflow', 'flip'
fadeEffect: { crossFade: true },
a11y: { enabled: true },
});