Scrollify 將頁面分割為多個全屏區塊,用戶滾動鼠標/觸屏滑動時自動吸附到下一區塊,適合單頁產品介紹、故事敘事、演示頁。依賴 jQuery 1.6+ 及 jQuery.easing 動畫庫。
<!DOCTYPE html>
<html><head>
<meta charset="utf-8">
<script src="jquery.js"></script>
<script src="jquery.easing.min.js"></script>
<script src="jquery.scrollify.min.js"></script>
</head><body>
<section id="section1">內容 1</section>
<section id="section2">內容 2</section>
<section id="section3">內容 3</section>
<script>
$(function() {
$.scrollify({ section: "section" });
});
</script>
</body></html>
$.scrollify({
section: "section", // 區塊選擇器
sectionName: "section-name", // data-section-name 屬性,用於 URL hash 導航
interstitialSection: "", // 非全屏區塊選擇器(如 header/footer)
easing: "easeOutExpo", // 動畫緩動函數(需 easing 插件)
scrollSpeed: 1100, // 滾動動畫毫秒數
offset: 0, // 像素偏移量
scrollbars: true, // 是否顯示滾動條
standardScrollElements: "", // 正常滾動的元素選擇器(如內部滾動容器)
setHeights: true, // 是否強制區塊高度 = 視口高度
overflowScroll: true, // 區塊內容超出視口時允許內部滾動
updateHash: true, // 滾動時更新 URL hash
touchScroll: true, // 移動端觸屏滑動支持
before: function(index, sections) {}, // 滾動開始前回調
after: function(index, sections) {}, // 滾動結束後回調
afterResize: function() {}, // 窗口縮放後回調
afterRender: function() {} // 初始化完成回調
});
| 方法 | 用法 | 說明 |
|---|---|---|
| move | $.scrollify("move", "#section2") | 程式化滾動到指定區塊(選擇器/索引/#name) |
| instantMove | $.scrollify("instantMove", 2) | 無動畫瞬間跳轉 |
| next/previous | $.scrollify("next") | 滾動到下一個/上一個區塊 |
| destroy | $.scrollify("destroy") | 銷毀實例,恢復原生滾動 |
| update | $.scrollify("update") | 動態增減區塊後重新計算 |
| current | $.scrollify("current") | 獲取當前區塊 jQuery 對象 |
| disable/enable | $.scrollify("disable") | 禁用/啟用滾動攔截 |
| isDisabled | $.scrollify("isDisabled") | 檢查是否禁用 |