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

簡要教程
jquery.caroursel.js是一款非常實用的可自動輪播的jQuery旋轉木馬插件。該旋轉木馬將圖片進行堆疊,輪流的將圖片推送到最前面來展示,形成旋轉木馬的效果。
使用方法
該jQuery旋轉木馬插件需要引入jQuery,jquery.carousel.js文件。
<script src="js/jquery.min.js"></script> <script src="js/jquery.carousel.js"></script>
HTML結構
該jQuery旋轉木馬插件使用一個<div>來作為包裹元素,在它里面是一個無序列表,用于放置圖片,以及兩個作為前后導航按鈕的<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樣式
你需要為該旋轉木馬特效添加下面的一些必要的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元素加載完畢之后,可以通過下面的方法來初始化該旋轉木馬插件。
Caroursel.init($('.caroursel'))
如果你需要自定義一些參數(shù),可以在頂層<div>元素中設置data-setting屬性。
<div class="caroursel rotator-main"
data-setting = '{
"width":1000, //旋轉木馬的寬度
"height":270, //旋轉木馬的高度
"posterWidth":640, //當前顯示的圖片的寬度
"posterHeight":270, //當前顯示的圖片的高度
"scale":0.8, //縮放值
"algin":"middle", //對齊方式
"speed":"1000", //動畫速度
"isAutoplay":"true", //自動播放
"dealy":"1000" //延遲時間
}'>
小提示:瀏覽器中如果不能正常運行,可以嘗試切換瀏覽模式。
為大家分享的jQuery實現(xià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自動輪播旋轉木馬插件</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自動輪播旋轉木馬插件</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實現(xiàn)自動輪播旋轉木馬特效代碼,希望大家可以喜歡,并應用到實踐中。
相關文章
jquery+ajax每秒向后臺發(fā)送請求數(shù)據(jù)然后返回頁面的代碼
jquery+ajax每秒向后臺發(fā)送請求數(shù)據(jù)然后返回頁面(包括jquery頁面加載完畢才執(zhí)行方法)2011-01-01
用戶管理的設計_jquery的ajax實現(xiàn)二級聯(lián)動效果
下面小編就為大家?guī)硪黄脩艄芾淼脑O計_jquery的ajax實現(xiàn)二級聯(lián)動效果。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07
輕松學習jQuery插件EasyUI EasyUI創(chuàng)建樹形網(wǎng)絡(1)
這篇文章主要幫助大家輕松學習jQuery插件EasyUI,并且教大家如何利用EasyUI創(chuàng)建樹形網(wǎng)絡,感興趣的小伙伴們可以參考一下2015-11-11
jQuery+C#實現(xiàn)參數(shù)RSA加密傳輸功能【附jsencrypt.js下載】
這篇文章主要介紹了jQuery+C#實現(xiàn)參數(shù)RSA加密傳輸功能,結合具體實例形式分析了js使用jsencrypt.js插件前端字符數(shù)據(jù)處理傳輸及C#后臺數(shù)據(jù)轉換與RSA加密相關操作技巧,并附帶jsencrypt.js供讀者下載參考使用,需要的朋友可以參考下2017-06-06

