分类分类
2015-11-03 14:43作者:zhao
本文实例讲述了jQuery实现自动轮播旋转木马特效。分享给大家供大家参考。具体如下:
这是一款基于jQuery实现自动轮播旋转木马特效代码,实现过程很简单。
简要教程
jquery.caroursel.js是一款非常实用的可自动轮播的jQuery旋转木马插件。该旋转木马将图片进行堆叠,轮流的将图片推送到最前面来展示,形成旋转木马的效果。
使用方法
该jQuery旋转木马插件需要引入jQuery,jquery.carousel.js文件。
<scriptsrc="js/jquery.min.js"></script>
<scriptsrc="js/jquery.carousel.js"></script>
HTML结构
该jQuery旋转木马插件使用一个<div>来作为包裹元素,在它里面是一个无序列表,用于放置图片,以及两个作为前后导航按钮的<div>元素。
<divclass="carourselrotator-demo">
<ulclass="rotator-list">
<liclass="rotator-item"><imgsrc="image/1.jpg"></li>
<liclass="rotator-item"><imgsrc="image/2.jpg"></li>
<liclass="rotator-item"><imgsrc="image/3.jpg"></li>
</ul>
<divclass="rotator-btnrotator-prev-btn"></div>
<divclass="rotator-btnrotator-next-btn"></div>
</div>
图片的数量需要为奇数张,否则显示会有一些异常,这是该插件的一个小bug。
CSS样式
你需要为该旋转木马特效添加下面的一些必要的CSS样式。
.rotator-main{
position:relative;
width:900px;
height:400px
}
.rotator-maina,.rotator-mainimg{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-repeatcentercenter;
background-color:red
}
.rotator-main.rotator-next-btn{
right:0px;
background:url("../image/btn_r.png")no-repeatcentercenter;
background-color:red
}
初始化插件
在页面DOM元素加载完毕之后,可以通过下面的方法来初始化该旋转木马插件。
Caroursel.init($('.caroursel'))
如果你需要自定义一些参数,可以在顶层<div>元素中设置data-setting属性。
<divclass="carourselrotator-main"
data-setting='{
"width":1000,//旋转木马的宽度
"height":270,//旋转木马的高度
"posterWidth":640,//当前显示的图片的宽度
"posterHeight":270,//当前显示的图片的高度
"scale":0.8,//缩放值
"algin":"middle",//对齐方式
"speed":"1000",//动画速度
"isAutoplay":"true",//自动播放
"dealy":"1000"//延迟时间
}'>
小提示:浏览器中如果不能正常运行,可以尝试切换浏览模式。
为大家分享的jQuery实现自动轮播旋转木马特效代码如下
<htmllang="zh">
<head>
<metacharset="UTF-8">
<metahttp-equiv="X-UA-Compatible"content="IE=edge,chrome=1">
<metaname="viewport"content="width=device-width,initial-scale=1.0">
<title>jQuery自动轮播旋转木马插件</title>
<linkrel="stylesheet"type="text/css"href="css/normalize.css"/>
<linkrel="stylesheet"type="text/css"href="css/default.css">
<linktype="text/css"rel="stylesheet"href="css/carousel.css">
<styletype="text/css">
.caroursel{margin:150pxauto;}
</style>
<!--[ifIE]>
<scriptsrc="http://libs.useso.com/js/html5shiv/3.7/html5shiv.min.js"></script>
<![endif]-->
</head>
<body>
<articleclass="htmleaf-container">
<headerclass="htmleaf-header">
<h1>jQuery自动轮播旋转木马插件</h1>
</header>
<divclass="carourselposter-main"data-setting='{
"width":1000,
"height":270,
"posterWidth":640,
"posterHeight":270,
"scale":0.8,
"dealy":"2000",
"algin":"middle"
}'>
<ulclass="poster-list">
<liclass="poster-item"><imgsrc="image/1.jpg"width="100%"height="100%"></li>
<liclass="poster-item"><imgsrc="image/2.jpg"width="100%"height="100%"></li>
<liclass="poster-item"><imgsrc="image/3.jpg"width="100%"height="100%"></li>
<liclass="poster-item"><imgsrc="image/4.jpg"width="100%"height="100%"></li>
<liclass="poster-item"><imgsrc="image/5.jpg"width="100%"height="100%"></li>
<liclass="poster-item"><imgsrc="image/6.jpg"width="100%"height="100%"></li>
<liclass="poster-item"><imgsrc="image/1.jpg"width="100%"height="100%"></li>
</ul>
<divclass="poster-btnposter-prev-btn"></div>
<divclass="poster-btnposter-next-btn"></div>
</div>
</article>
<script>window.jQuery||document.write('<scriptsrc="js/jquery-2.1.1.min.js"></script>')</script>
<scriptsrc="js/jquery.carousel.js"></script>
<script>
Caroursel.init($('.caroursel'))
</script>
</body>
</html>
为大家分享的jQuery实现自动轮播旋转木马特效代码,希望大家可以喜欢,并应用到实践中。
相关