资讯专栏INFORMATION COLUMN

简单的图片轮播

BlackFlagBin / 891人阅读

摘要:效果功能左右箭头切换状态控制点切换鼠标悬念自动轮播广西南宁低价供应各种地被绿化苗木等广西南宁低价供应各种地被绿化苗木等广西南宁低价供应各种地被绿化苗木等

效果:

功能:
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 #ffffd;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"; } else { statusList += "
  • "; } } statusList += "
"; $(conf.box).append(statusList); // 添加左右按钮 var btns = "<>"; $(conf.box).append(btns); // 索引 var index = 0; // 切换函数 function switchFunc(curIndex) { 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"); } // 自动播放 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();

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/83227.html

相关文章

  • 手把手和你用原生JS写一个循环播放图片轮播

    摘要:前段时间学习了淘宝首页的静态页面,其中收获较大的的就是这个循环播放的图片轮播组件,本文就将相关制作经验分享给大家。作为演示,用标签代替了图片。关键使用不同背景色的替代图片。 前段时间学习了淘宝首页的静态页面,其中收获较大的的就是这个循环播放的图片轮播组件,本文就将相关制作经验分享给大家。 先看看在线DEMO:原生JS循环播放图片轮播组件 (支持IE8+,本文中的在线demo均未经过压缩...

    enda 评论0 收藏0
  • 手把手和你用原生JS写一个循环播放图片轮播

    摘要:前段时间学习了淘宝首页的静态页面,其中收获较大的的就是这个循环播放的图片轮播组件,本文就将相关制作经验分享给大家。作为演示,用标签代替了图片。关键使用不同背景色的替代图片。 前段时间学习了淘宝首页的静态页面,其中收获较大的的就是这个循环播放的图片轮播组件,本文就将相关制作经验分享给大家。 先看看在线DEMO:原生JS循环播放图片轮播组件 (支持IE8+,本文中的在线demo均未经过压缩...

    dendoink 评论0 收藏0
  • 手把手和你用原生JS写一个循环播放图片轮播

    摘要:前段时间学习了淘宝首页的静态页面,其中收获较大的的就是这个循环播放的图片轮播组件,本文就将相关制作经验分享给大家。作为演示,用标签代替了图片。关键使用不同背景色的替代图片。 前段时间学习了淘宝首页的静态页面,其中收获较大的的就是这个循环播放的图片轮播组件,本文就将相关制作经验分享给大家。 先看看在线DEMO:原生JS循环播放图片轮播组件 (支持IE8+,本文中的在线demo均未经过压缩...

    gityuan 评论0 收藏0
  • 实现简单轮播

    摘要:小练习轮播图组件任务描述在和上一任务同一目录下面创建一个文件,在目录中创建,并在其中编码,实现一个轮播图的功能。实现思路考察对节点,定时器,事件的处理。 小练习3:轮播图组件 任务描述在和上一任务同一目录下面创建一个task0002_3.html文件,在js目录中创建task0002_3.js,并在其中编码,实现一个轮播图的功能。 图片数量及URL均在HTML中写好 可以配置轮播的顺...

    EsgynChina 评论0 收藏0
  • 简单无缝轮播

    摘要:昨天学习了轮播的原理,今天再来看看无缝轮播的技术。无缝轮播无缝轮播的原来大致类似小时候跳大绳,小朋友一个个进入,一个个出来,出来后排到队伍末尾,等在着进入,无缝轮播也类似这种机制。 昨天学习了轮播的原理,今天再来看看无缝轮播的技术。 昨天学习的轮播机制类似于走马灯,所有图片排成一排,轮流在你眼前走过,你就会感觉他们动起来了,今天学的无缝轮播就不能用昨天的思路了,它和昨天最大的区别是,从...

    Kyxy 评论0 收藏0
  • html学习之路--简单图片轮播

    摘要:一个简单的图片轮播效果页面代码,基本的结构,在中显示图片,此处图片依次命名为。简单图片轮播然后对网页进行一个非常简单的美化。具体到元素标签最后是文件对图片轮播进行控制。一个简单的图片轮播效果 photo.html页面代码,基本的HTML结构,在main中显示图片,此处图片依次命名为1.jpg、2.jpg、3.jpg、4.jpg。 1 DOCTYPE html> 2 3 ...

    番茄西红柿 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<