DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> WEB網站前端 >> 網頁特效代碼
JS 縱向圓點導航的圖片輪播
編輯:網頁特效代碼     

常見的輪播把數字指示器橫排在圖片下方,這個版本改成縱向圓點貼在側邊,視覺上更類似雜誌或作品集網站的翻頁提示,也不佔用額外的垂直空間。

線上體驗

https://hovertree.com/texiao/js/1.htm

HTML 檔程式碼

<!DOCTYPE html>
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
 <meta charset="utf-8"/>
 <title>JS縱軸圓點的圖片輪播切換 - 何問起 HoverTree</title><base target="_blank" />
 <link rel="stylesheet" type="text/css" href="https://hovertree.com/texiao/js/1/css/style.css">
 <script type="text/javascript" src="https://hovertree.com/texiao/js/1/js/koala.min.1.5.js"></script>
 <script type="text/javascript">
 Qfast.add('widgets', { path: "https://hovertree.com/texiao/js/1/js/terminator2.2.min.js", type: "js", requires: ['fx'] });
 Qfast(false, 'widgets', function () {
 K.tabs({
 id: 'decoroll2', //焦點圖包裹id
 conId: "decoimg_a2", //大圖域包裹id
 tabId: "deconum2", //小圓點數字提示id
 tabTn: "a",
 conCn: '.decoimg_b2', //大圖域配置class
 auto: 1, //自動播放 1或0
 effect: 'fade', //效果配置
 eType: 'mouseover', // 鼠標事件
 pageBt: true, //是否有按鈕切換頁碼
 bns: ['.prev', '.next'], //前後按鈕配置class
 interval: 3000// 停頓時間
 })
 })
 </script>
</head>
<body>
 <div><a href="https://hovertree.com">首頁</a> <a href="https://hovertree.com/hvtart/bjae/f03e85410878db53.htm">原文</a>
 <a href="https://hovertree.com/texiao/">特效庫</a>
 </div>
 <div id="decoroll2" class="imgfocus">
 <div id="decoimg_a2" class="imgbox">
 <div class="decoimg_b2">
 <a href="https://hovertree.com/hvtart/bjae/f03e85410878db53.htm">
 <img src="https://hovertree.com/texiao/js/1/img/1.jpg">
 </a>
 </div>
 <div class="decoimg_b2">
 <a href="https:///">
 <img src="https://hovertree.com/texiao/js/1/img/2.jpg">
 </a>
 </div>
 <div class="decoimg_b2">
 <a href="https://hovertree.com/shortanswer/">
 <img src="https://hovertree.com/texiao/js/1/img/3.jpg">
 </a>
 </div>
 <div class="decoimg_b2">
 <a href="https://hovertree.com/guestbook/">
 <img src="https://hovertree.com/texiao/js/1/img/4.jpg">
 </a>
 </div>
 </div>
 <ul id="deconum2" class="num_a2">
 <li><a href="javascript:void(0)" hidefocus="true" target="_self">楊冪</a></li>
 <li><a href="javascript:void(0)" hidefocus="true" target="_self">范冰冰</a></li>
 <li><a href="javascript:void(0)" hidefocus="true" target="_self">高圓圓</a></li>
 <li><a href="javascript:void(0)" hidefocus="true" target="_self">劉詩詩</a></li>
 </ul>
 </div>
 <br />
</body>
</html>

參數怎麼調

K.tabs() 把輪播需要的控制項都開放出來了,幾個實用的:

  • auto: 1 開啟自動播放,設 0 則變成純手動。
  • interval: 3000 每張停留 3 秒,單位是毫秒。想讓使用者有時間看完圖再換,可以拉到 4000~5000。
  • effect: 'fade' 淡入淡出。改成滑動類型的關鍵字則會變成位移切換。
  • eType: 'mouseover' 觸發方式是滑過。改成 click 可以避免使用者滑過時被強制切頁。
  • pageBt: true 與 bns: ['.prev', '.next'] 搭配使用,決定要不要顯示左右箭頭以及箭頭的 class 名稱。

結構上的巧思

大圖區 #decoimg_a2 與指示器 #deconum2 是分開的兩個容器,靠 conCn<li> 配對。這意味著指示器的文字內容可以寫有意義的名稱(這裡用藝名),而不只是 1、2、3、4,對使用者更友善。

另外每個 <a> 都寫了 href="javascript:void(0)" 與 hidefocus="true",前者避免點擊時跳頁或捲到頂端,後者則是舊版 IE 用來消除點擊後虛線框的寫法。

可讀性上的建議

如果要在正式專案使用,建議加上鍵盤操作(左右方向鍵換頁)與 aria-label 標註,讓螢幕閱讀器能念出「第幾張,共幾張」。同時記得為輪播提供暫停按鈕,這既是無障礙規範的要求,也能避免自動播放干擾閱讀。

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