博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
简单的图片轮播
阅读量:6871 次
发布时间:2019-06-26

本文共 5664 字,大约阅读时间需要 18 分钟。

效果:

图片描述

功能:

1、左右箭头切换
2、状态控制点切换
3、鼠标悬念
4、自动轮播

HTML:

CSS:

.zh-carousel{position: relative;width: 100%;height: 246px;}.zh-carousel .zh-img-list{position: relative;z-index: 2;width: 100%;height: 100%;overflow: hidden;}.zh-carousel .zh-img-list ul{height: 100%;}.zh-carousel .zh-img-list li{position: absolute;z-index: 0;left: 0;top: 0;width: 100%;height: 100%;}.zh-carousel .zh-img-list .active{z-index: 1;}.zh-carousel .zh-img-list li a{display: block;position: relative;height: 100%;}.zh-carousel .zh-img-list li img{display: block;width: 100%;height: 100%;opacity: 0;filter:Alpha(opacity=0);-webkit-transition: all .5s ease-out;transition: all .5s ease-out;}.zh-carousel .zh-img-list .active img{opacity: 1;filter:Alpha(opacity=100);}.zh-carousel .zh-img-list li .zh-desc{display: block;position: absolute;z-index: 3;left: 0;bottom: -36px;width: 100%;padding: 10px 15px;box-sizing: border-box;background-color: rgba(0,0,0,0.5);font-size: 14px;color: #fff;-webkit-transition: all .5s ease-out;transition: all .5s ease-out;white-space: nowrap;text-overflow: ellipsis;overflow: hidden;}.zh-carousel .zh-img-list .active .zh-desc{bottom: 0;}.zh-carousel .zh-status-list{position: absolute;z-index: 4;left: 0;top: 0;width: 100%;padding: 10px 15px;box-sizing: border-box;text-align: right;}.zh-carousel .zh-status-list li{display: inline-block;width: 10px;height: 10px;margin-left: 5px;background-color: #fff;border: 1px solid #ddd;cursor: pointer;}.zh-carousel .zh-status-list .active{background-color: #FFD8C6;border: 1px solid #ED713D;}.zh-carousel .zh-prev,.zh-carousel .zh-next{display: inline-block;position: absolute;z-index: 4;top: 50%;-webkit-transform: translate(0, -50%);transform: translate(0, -50%);width: 20px;height: 30px;background-color: rgba(0,0,0,0.5);font-family: "SimSun";font-size: 18px;font-weight: bold;color: #fff;text-align: center;line-height: 30px;cursor: pointer;}.zh-carousel .zh-prev:hover,.zh-carousel .zh-next:hover {background-color: rgba(0,0,0,0.75);}.zh-carousel .zh-prev{left: 0;}.zh-carousel .zh-next{right: 0;}

JS:

$.extend({    /*        图片轮播        @param options object (配置项)    */    carousel: function(options) {        var defaults = {            box: '.zh-carousel',               // 盒子            listBox: '.zh-img-list',      // 列表框            stateBox: '.zh-status-list',    // 状态框            prev: '.zh-prev',         // 上一个            next: '.zh-next',         // 下一个            time: 2000                   // 动画时间        }        var conf = $.extend({}, defaults, options);        // 给第一个添加状态        $(conf.box).find(conf.listBox).find('li:first').addClass('active');        // 获取图片的数量        var liNum = $(conf.box).find(conf.listBox).find('li').size();        // 添加状态列表        var statusList = '
    '; for(var i=0; i
    liNum - 1) { index = 0; } $(conf.box).find(conf.stateBox).find('li').eq(index).addClass('active').siblings().removeClass('active'); $(conf.box).find(conf.listBox).find('li').eq(index).addClass('active').siblings().removeClass('active'); } // 自动播放 var autoPlay = setInterval(function() { switchFunc(index); }, conf.time); // 鼠标悬停 $(conf.box).find(conf.listBox).mouseover(function() { clearInterval(autoPlay); }).mouseout(function() { autoPlay = setInterval(function() { switchFunc(index); }, conf.time); }); // 控制点 $(conf.box).find(conf.stateBox).find('li').mouseover(function() { clearInterval(autoPlay); }).mouseout(function() { autoPlay = setInterval(function() { switchFunc(index); }, conf.time); }).click(function() { $(this).addClass('active').siblings().removeClass('active'); $(conf.box).find(conf.listBox).find('li').eq($(this).index()).addClass('active').siblings().removeClass('active'); index = $(this).index(); }); // 点击左箭头 $(conf.box).find(conf.prev).mouseover(function() { clearInterval(autoPlay); }).mouseout(function() { autoPlay = setInterval(function() { switchFunc(index); }, conf.time); }).click(function() { index--; if(index < 0) { index = liNum - 1; } $(conf.box).find(conf.stateBox).find('li').eq(index).addClass('active').siblings().removeClass('active'); $(conf.box).find(conf.listBox).find('li').eq(index).addClass('active').siblings().removeClass('active'); }); // 点击右箭头 $(conf.box).find(conf.next).mouseover(function() { clearInterval(autoPlay); }).mouseout(function() { autoPlay = setInterval(function() { switchFunc(index); }, conf.time); }).click(function() { index++; if(index > liNum-1) { index = 0; } $(conf.box).find(conf.stateBox).find('li').eq(index).addClass('active').siblings().removeClass('active'); $(conf.box).find(conf.listBox).find('li').eq(index).addClass('active').siblings().removeClass('active'); }); }});// 调用$.carousel();

转载地址:http://eqpfl.baihongyu.com/

你可能感兴趣的文章
PHP开发者常犯的10个MySQL错误
查看>>
物联网在交通领域示范应用的三大趋势
查看>>
浅谈如何用Java操作MongoDB?
查看>>
Java ConcurrentModificationException异常原因和解决方法
查看>>
2015 年对 GitLab 来说是非常棒的一年
查看>>
《编写高质量代码:改善c程序代码的125个建议》——建议17-1:先处理正常情况,再处理异常情况...
查看>>
《Docker技术入门与实战》——3.2 查看镜像信息
查看>>
Linux有问必答:如何在CentOS或RHEL 7上修改主机名
查看>>
JVM的持久代——何去何从?
查看>>
Kafka Producer接口
查看>>
《jQuery、jQuery UI及jQuery Mobile技巧与示例》——9.8 技巧:指定自定义的过渡动画...
查看>>
《NLTK基础教程——用NLTK和Python库构建机器学习应用》——第2章 文本的歧义及其清理...
查看>>
《Hack与HHVM权威指南》——1.3.3 属性
查看>>
MongoDB Schema Design
查看>>
基于Quick BI的用户分布分析
查看>>
对《架构即未来:现代企业可扩展的web架构、流程和组织》这本书的读后感。...
查看>>
微服务架构的分布式事务解决方案
查看>>
Spark修炼之道(高级篇)——Spark源码阅读:第五节 Stage提交
查看>>
iOS8到iOS9 变化笔记
查看>>
Linux之iconv转换文本格式的问题
查看>>