首页 技术 正文
技术 2022年11月20日
0 收藏 949 点赞 3,469 浏览 3627 个字

  首先说下,我在网上找的例子全是用的UL 实现,其实大可不必,只要是能包含img标签的HTML标签都可以做轮播效果。利用jquery的淡入淡出函数(fadeIn和fadeOut)。废话也不多说,边上代码边讲解。最后附上demo效果地址。

  <!–整体容器–>
    <div class=”imgbox”>
        <!–图片列表,除第一张显示外,其余隐藏–>
        <ul>
            <li style=”display: block;” title=”清灵少女宛如梦境仙女”><a href=”#”>
                <img src=”https://img.zhankr.net/3yhmuvipews273534.jpg” /></a></li>
            <li title=”美女海边性感透视装诱惑”><a href=”#”>
                <img src=”https://img.zhankr.net/25ahhaanwpl273535.jpg” /></a></li>
            <li title=”夏小薇:百变小魔女变身性感数码宝贝”><a href=”#”>
                <img src=”https://img.zhankr.net/tvxjzembg5e273536.jpg” /></a></li>
            <li title=”夏小薇化身《杀破狼》粉色妖姬鲜嫩欲滴”><a href=”#”>
                <img src=”https://img.zhankr.net/ulkzo3ory0h273537.jpg” /></a></li>
        </ul>
        <div class=”title_bg common”><!–图片标题背景–>
        </div>
        <!–图片显示标题–>
        <div class=”title common”></div>
        <!–图片序号–>
        <div class=”pager common”>
            <ul>
                <li>4</li>
                <li>3</li>
                <li>2</li>
                <li style=”background: #FF70Ad;”>1</li>
            </ul>
        </div>
    </div>

//css

img{border-style:none;}
.imgbox{width:530px;margin:100px;height:350px;}
.imgbox img{width:530px;height:350px;}
.imgbox ul{list-style-type:none;margin:0px;padding:0px;}
.imgbox ul li{display:none;}
.title_bg{z-index:1;background-color:#000;filter:alpha(opacity=30);-moz-opacity:0.3;opacity:0.3;}
.title{z-index:2;color:#FFF;text-indent:10px;font-size:14px;line-height:40px;}
.pager{z-index:3;}
.common{position:relative;height:40px;margin-top:-43px;}
.pager ul{margin-top:5px;}
.pager ul li{float:right;color:#FFF;font-size:15px;display:block;border:2px solid #e5eaff;width:25px;height:25px;margin-right:4px;margin-top:5px;text-align:center;line-height:25px;background-color:#6f4f67;cursor:pointer;}

//js

$(document).ready(function () {             (new CenterImgPlay()).Start();         });         function CenterImgPlay() {             this.list = $(“.imgbox”).children(“:first”).children();             this.indexs = [];             this.length = this.list.length;             //图片显示时间             this.timer = 3000;             this.showTitle = $(“.title”);

var index = 0, self = this, pre = 0, handid, isPlay = false, isPagerClick = false;

this.Start = function () {                 this.Init();                 //计时器,用于定时轮播图片                 handid = setInterval(self.Play, this.timer);             };             //初始化             this.Init = function () {                 var o = $(“.pager ul li”), _i;

for (var i = o.length – 1, n = 0; i >= 0; i–, n++) {                     this.indexs[n] = o.eq(i).click(self.PagerClick);                 }             };             this.Play = function () {                 isPlay = true;                 index++;                 if (index == self.length) {                     index = 0;                 }                 //先淡出,在回调函数中执行下一张淡入                 self.list.eq(pre).fadeOut(300, “linear”, function () {                     var info = self.list.eq(index).fadeIn(500, “linear”, function () {                         isPlay = false;                         if (isPagerClick) { handid = setInterval(self.Play, self.timer); isPagerClick = false; }                     }).attr(“title”);                     //显示标题                     self.showTitle.text(info);                     //图片序号背景更换                     self.indexs[index].css(“background-color”, “#FF70Ad”);                     self.indexs[pre].css(“background-color”, “#6f4f67”);

pre = index;                 });             };             //图片序号点击             this.PagerClick = function () {                 if (isPlay) { return; }                 isPagerClick = true;

clearInterval(handid);

var oPager = $(this), i = parseInt(oPager.text()) – 1;

if (i != pre) {                     index = i – 1;                     self.Play();                 }             };         };

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,078
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,553
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,402
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,177
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,814
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898