基于jQuery實(shí)現(xiàn)自動輪播旋轉(zhuǎn)木馬特效
本文實(shí)例講述了jQuery實(shí)現(xiàn)自動輪播旋轉(zhuǎn)木馬特效。分享給大家供大家參考。具體如下:
這是一款基于jQuery實(shí)現(xiàn)自動輪播旋轉(zhuǎn)木馬特效代碼,實(shí)現(xiàn)過程很簡單。
運(yùn)行效果圖: -------------------查看效果 下載源碼-------------------

簡要教程
jquery.caroursel.js是一款非常實(shí)用的可自動輪播的jQuery旋轉(zhuǎn)木馬插件。該旋轉(zhuǎn)木馬將圖片進(jìn)行堆疊,輪流的將圖片推送到最前面來展示,形成旋轉(zhuǎn)木馬的效果。
使用方法
該jQuery旋轉(zhuǎn)木馬插件需要引入jQuery,jquery.carousel.js文件。
<script src="js/jquery.min.js"></script> <script src="js/jquery.carousel.js"></script>
HTML結(jié)構(gòu)
該jQuery旋轉(zhuǎn)木馬插件使用一個<div>來作為包裹元素,在它里面是一個無序列表,用于放置圖片,以及兩個作為前后導(dǎo)航按鈕的<div>元素。
<div class="caroursel rotator-demo"> <ul class="rotator-list"> <li class="rotator-item"><img src="image/1.jpg"></li> <li class="rotator-item"><img src="image/2.jpg"></li> <li class="rotator-item"><img src="image/3.jpg"></li> </ul> <div class="rotator-btn rotator-prev-btn"></div> <div class="rotator-btn rotator-next-btn"></div> </div>
圖片的數(shù)量需要為奇數(shù)張,否則顯示會有一些異常,這是該插件的一個小bug。
CSS樣式
你需要為該旋轉(zhuǎn)木馬特效添加下面的一些必要的CSS樣式。
.rotator-main {
position: relative;
width: 900px;
height: 400px
}
.rotator-main a, .rotator-main img { display: block; }
.rotator-main .rotator-list {
width: 900px;
height: 400px
}
.rotator-main .rotator-list .rotator-item {
position: absolute;
left: 0px;
top: 0px
}
.rotator-main .rotator-btn {
position: absolute;
height: 100%;
width: 100px;
top: 0px;
z-index: 10;
opacity: 0;
}
.rotator-main .rotator-prev-btn {
left: 0px;
background: url("../image/btn_l.png") no-repeat center center;
background-color: red
}
.rotator-main .rotator-next-btn {
right: 0px;
background: url("../image/btn_r.png") no-repeat center center;
background-color: red
}
初始化插件
在頁面DOM元素加載完畢之后,可以通過下面的方法來初始化該旋轉(zhuǎn)木馬插件。
Caroursel.init($('.caroursel'))
如果你需要自定義一些參數(shù),可以在頂層<div>元素中設(shè)置data-setting屬性。
<div class="caroursel rotator-main"
data-setting = '{
"width":1000, //旋轉(zhuǎn)木馬的寬度
"height":270, //旋轉(zhuǎn)木馬的高度
"posterWidth":640, //當(dāng)前顯示的圖片的寬度
"posterHeight":270, //當(dāng)前顯示的圖片的高度
"scale":0.8, //縮放值
"algin":"middle", //對齊方式
"speed":"1000", //動畫速度
"isAutoplay":"true", //自動播放
"dealy":"1000" //延遲時(shí)間
}'>
小提示:瀏覽器中如果不能正常運(yùn)行,可以嘗試切換瀏覽模式。
為大家分享的jQuery實(shí)現(xiàn)自動輪播旋轉(zhuǎn)木馬特效代碼如下
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery自動輪播旋轉(zhuǎn)木馬插件</title>
<link rel="stylesheet" type="text/css" href="css/normalize.css" />
<link rel="stylesheet" type="text/css" href="css/default.css">
<link type="text/css" rel="stylesheet" href="css/carousel.css">
<style type="text/css">
.caroursel{margin:150px auto;}
</style>
<!--[if IE]>
<script src="http://libs.useso.com/js/html5shiv/3.7/html5shiv.min.js"></script>
<![endif]-->
</head>
<body>
<article class="htmleaf-container">
<header class="htmleaf-header">
<h1>jQuery自動輪播旋轉(zhuǎn)木馬插件</h1>
</header>
<div class = "caroursel poster-main" data-setting = '{
"width":1000,
"height":270,
"posterWidth":640,
"posterHeight":270,
"scale":0.8,
"dealy":"2000",
"algin":"middle"
}'>
<ul class = "poster-list">
<li class = "poster-item"><img src="image/1.jpg" width = "100%" height="100%"></li>
<li class = "poster-item"><img src="image/2.jpg" width = "100%" height="100%"></li>
<li class = "poster-item"><img src="image/3.jpg" width = "100%" height="100%"></li>
<li class = "poster-item"><img src="image/4.jpg" width = "100%" height="100%"></li>
<li class = "poster-item"><img src="image/5.jpg" width = "100%" height="100%"></li>
<li class = "poster-item"><img src="image/6.jpg" width = "100%" height="100%"></li>
<li class = "poster-item"><img src="image/1.jpg" width = "100%" height="100%"></li>
</ul>
<div class = "poster-btn poster-prev-btn"></div>
<div class = "poster-btn poster-next-btn"></div>
</div>
</article>
<script>window.jQuery || document.write('<script src="js/jquery-2.1.1.min.js"><\/script>')</script>
<script src="js/jquery.carousel.js"></script>
<script>
Caroursel.init($('.caroursel'))
</script>
</body>
</html>
為大家分享的jQuery實(shí)現(xiàn)自動輪播旋轉(zhuǎn)木馬特效代碼,希望大家可以喜歡,并應(yīng)用到實(shí)踐中。
- jquery實(shí)現(xiàn)簡單自動輪播圖效果
- jquery實(shí)現(xiàn)定時(shí)自動輪播特效
- jquery帶有索引按鈕且自動輪播切換特效代碼分享
- JQuery實(shí)現(xiàn)的圖文自動輪播效果插件
- 12款經(jīng)典的白富美型—jquery圖片輪播插件—前端開發(fā)必備
- Jquery代碼實(shí)現(xiàn)圖片輪播效果(一)
- 原生js和jquery實(shí)現(xiàn)圖片輪播特效
- jQuery圖片輪播的具體實(shí)現(xiàn)
- 基于JQuery的實(shí)現(xiàn)圖片輪播效果(焦點(diǎn)圖)
- jquery實(shí)現(xiàn)圖片自動輪播效果
相關(guān)文章
jQuery實(shí)現(xiàn)html可聯(lián)動的百分比進(jìn)度條
這篇文章主要介紹了jQuery實(shí)現(xiàn)html可聯(lián)動的百分比進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-03-03
jquery中dom操作和事件的實(shí)例學(xué)習(xí)-表單驗(yàn)證
這個demo的效果是實(shí)現(xiàn)用戶輸入時(shí)提供實(shí)時(shí)提醒,并不一定要等到元素失去焦點(diǎn)時(shí)才提醒2011-11-11
jQuery EasyUI 右鍵菜單--關(guān)閉標(biāo)簽/選項(xiàng)卡的簡單實(shí)例
下面小編就為大家?guī)硪黄猨Query EasyUI 右鍵菜單--關(guān)閉標(biāo)簽/選項(xiàng)卡的簡單實(shí)例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-10-10
jquery 與NVelocity 產(chǎn)生沖突的解決方法
有時(shí)候使用jquery 與NVelocity的時(shí)候,會產(chǎn)生沖突,下面是具體的解決方法,需要的朋友可以參考下。2011-06-06
jquery插件star-rating.js實(shí)現(xiàn)星級評分特效
Bootstrap Star Rating是一個簡單而強(qiáng)大的jQuery插件實(shí)現(xiàn)星級分?jǐn)?shù)評級。支持像分?jǐn)?shù)星填充和RTL輸入先進(jìn)的功能。在利用純CSS-3造型使控制重點(diǎn)開發(fā)。該插件使用引導(dǎo)標(biāo)記和造型默認(rèn)情況下,但它可以覆蓋與其他任何CSS的標(biāo)記。2015-04-04

