DIV CSS 佈局教程網

jQuery 圓形旋轉圖片滾動切換效果
編輯:JQuery特效代碼     

這個效果比較特別也活潑,一般網站上不多見,有興趣的朋友可以下載後自行取用。經過修改後已相容主流瀏覽器。

效果預覽:

線上示範:https://demo.jb51.net/js/ImagesRotateScroll/index.html

Step 1. 建立 HTML

結構分三層:外層 #rotatescroll 是舞台,.viewport 負責裁切,.overview 則是水平排列所有圖片的清單。另外還有一層遮罩與一個可拖曳的旋鈕。

<div id="rotatescroll">
    <div class="viewport">
        <ul class="overview">
            <li><img src="images/SF1.jpg" alt="Chun-Li" /></li>
            <li><img src="images/SF2.jpg" alt="VEGA" /></li>
            <li><img src="images/SF3.jpg" alt="DHAISIM" /></li>
            <!-- 依此類推至 SF15 -->
        </ul>
    </div>
    <div class="overlay"></div>
    <div class="thumb"></div>
</div>

Step 2. 建立 CSS

關鍵是 .overview 給一個足夠寬的絕對定位寬度,讓所有 li 橫向排成一列,再由 .viewport 的 overflow: hidden 裁出圓形視窗。

#rotatescroll {
    width: 300px; height: 300px;
    margin: 0 auto; position: relative;
}
#rotatescroll .viewport{
    width: 300px; height: 300px;
    position: relative; margin: 0 auto; overflow: hidden;
}
#rotatescroll .overview {
    width: 798px;                 /* 容納所有圖片的總寬 */
    position: absolute; list-style: none;
    margin: 0; padding: 0; left: 0; top: 0;
}
#rotatescroll .overview li {
    width: 300px; height: 300px;
    float: left; position: relative;
}
#rotatescroll .overlay {
    height: 300px; width: 300px;
    background: url(../images/bg-rotatescroll.png) no-repeat 0 0;
    position: absolute; left: 0; top: 0;
}
#rotatescroll .thumb {
    width: 26px; height: 26px; z-index: 200;
    background: url(../images/bg-thumb.png) no-repeat 50% 50%;
    position: absolute; top: 0px; cursor: pointer; left: 0px;
}
#rotatescroll .dot {
    background: url(../images/bg-dot2.png) no-repeat 0 0;
    display: none; height: 12px; width: 12px;
    position: absolute; left: 155px; top: 3px; z-index: 100;
}
#rotatescroll .dot span { display: none; }

Step 3. 引入 jQuery 與腳本

<script type="text/javascript" src="https://www.baijs.nl/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery.tinycircleslider.js"></script>
<script type="text/javascript" src="js/website.js"></script>

運作原理

核心插件是 tinycircleslider:使用者拖曳 .thumb 旋鈕時,插件依拖曳比例換算出應該位移的像素值,再平移 .overview。因為所有圖片早已橫向排好,平移就等於輪播;而遮罩圖 bg-rotatescroll.png 疊在上層,讓邊緣產生弧度與陰影,視覺上就變成了「圓筒裡轉動」的效果。

檔案打包下載:https://www.jb51.net/jiaoben/34107.html

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