jQuery实现带进度条的轮播图


Posted in jQuery onSeptember 13, 2020

本文实例为大家分享了jQuery实现带进度条轮播图的具体代码,供大家参考,具体内容如下

1.html模块

<div class="banner">
 <ul>
 <li style="background: url(img/bg1.jpg) center;">
  <img src="img/con1.png" />
  <div class="nav"></div>
  <div class="bar">
  <p></p>
  </div>
 </li>
 <li style="background: url(img/bg2.jpg) center;">
  <img src="img/con2.png" />
  <div class="nav"></div>
  <div class="bar">
  <p></p>
  </div>
 </li>
 <li style="background: url(img/bg3.jpg) center;">
  <img src="img/con3.png" />
  <div class="nav"></div>
  <div class="bar">
  <p></p>
  </div>
 </li>
 </ul>
</div>

2.css模块

<style type="text/css">
 *{
 margin: 0;
 padding: 0;
 list-style: none;
 }
 .banner{
 width: 100%;
 height: 600px;
 position: relative;
 }
 ul li{
 width: 100%;
 height: 600px;
 position: absolute;
 top: 0;
 left: 0;
 overflow:hidden;
 }
 ul li img{
 width: 100%;
 height: 600px;
 position: absolute;
 left: -100%;
 }
 .nav{
 width: 100%;
 height: 70px;
 background: rgba(255,255,255,0.3);
 position: absolute;
 bottom: 0;
 }
 .bar{
 width: 80%;
 height: 3px;
 background-color: #999;
 position: absolute;
 bottom: 0;
 left: 10%;
 }
 .bar p{
 width: 0px;
 height: 3px;
 background-color: green;
 }
</style>

3.jQuery模块

<script src="js/jquery-3.5.1.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
 var i=0;//定义当前索引
 imgChange();//初始化调用
 //定时切换
 setInterval("imgChange()",6000);
 //图片轮播的函数
 function imgChange(){
 //进度条完成后显示下一张背景
 $("ul li").eq(i).fadeIn(100).siblings().fadeOut(100);
 //初始化文字图片---设置到外部
 $("ul li").eq(i).find("img").css("left","-100%");
 //初始化进度条
 $("ul li").eq(i).find("p").css("width","0px");
 //设置文字图片从左进入的动画
 $("ul li").eq(i).find("img").animate({"left":"0px"},500,function(){
  //设置进度条动画
  $("ul li").eq(i).find("p").animate({"width":"100%"},5000,function(){
  $("ul li").eq(i).find("img").animate({left:"100%"},400);
  //改变当前索引,当索引为最后一个则设为0,否则就加一
  if(i>=$("ul li").length-1){
  i=0
  }else{
  i++;
  }
  })
 })
 }
</script>

4.方法二

<!DOCTYPE html>
<html>
 <head>
 <meta charset="UTF-8">
 <title>带进度条的轮播图</title>
 <script src="js/jquery-3.5.1.js" type="text/javascript" charset="utf-8"></script>
 <script type="text/javascript">
 $(function () {
 // 初始环境
 var i=0,m;
 tin(i);
 // 定时器
 m=setInterval(function () {
  if (i>=2) {
  i=0;
  }else{
  i++; 
  }
  tin(i);
 },5000);
 })
 // 动画效果
 var tin = function (i) {
  $(".cont li").eq(i).find("img").css("left","-100%");
  $(".bar span").css("width","0%");
  $(".cont li").eq(i).fadeIn(100).siblings().fadeOut(100);
  $(".cont li").eq(i).find("img").animate({left:"0%"},1000);
  $(".bar span").animate({width:"100%"},4500,function () {
  $(".cont li").eq(i).find("img").animate({left:"100%"},400);
  });
 }
 </script>
 <style type="text/css">
 *{
 margin: 0;
 padding: 0;
 list-style: none;
 }
 .box{
 width: 100%;
 height: 630px;
 position: relative;
 }
 .cont{
 width: 100%;
 height: 630px;
 position: relative;
 overflow: hidden;
 }
 .cont li{
 width: 100%;
 height: 630px;
 position: absolute;
 top: 0;
 left: 0;
 }
 .bar{
 width: 70%;
 height: 3px;
 position: absolute;
 bottom: 0px;
 left: 15%;
 background-color: white;
 border-radius: 50px;
 }
 .bar span{
 width: 0px;
 display: block;
 height: 80%;
 background-color: green;
 border-radius: 50px;
 }
 .cont li img{
 width: 100%;
 height: 630px;
 position: absolute;
 left: -100%;
 top: 0;
 }
 .con1{
 background: url(img/bg1.jpg) center;
 }
 .con2{
 background: url(img/bg2.jpg) center;
 }
 .con3{
 background: url(img/bg3.jpg) center;
 }
 .pav{
 width: 100%;
 height: 70px;
 position: absolute;
 bottom: 0px;
 background-color: rgba(255,255,255,0.3);
 }
 </style>
 </head>
 <body>
 <div id="main">
 <div id="box" class="box">
 <!--图片-->
 <ul class="cont">
  <li class="con1"><img src="img/con1.png"/></li>
  <li class="con2"><img src="img/con2.png"/></li>
  <li class="con3"><img src="img/con3.png"/></li>
 </ul>
 <div class="pav"></div>
 <!--进度条-->
 <div class="bar">
  <span></span>
 </div>
 </div>
 </div>
 </body>
</html>

精彩专题分享:jQuery图片轮播 JavaScript图片轮播 Bootstrap图片轮播

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

jQuery 相关文章推荐
利用jQuery解析获取JSON数据
Apr 08 jQuery
jQuery实现倒计时功能 jQuery实现计时器功能
Sep 19 jQuery
JQuery选中select组件被选中的值方法
Mar 08 jQuery
jQuery实现模糊查询的方法分析
May 10 jQuery
jQuery实现table表格checkbox全选的方法分析
Jul 04 jQuery
jQuery插件实现弹性运动完整示例
Jul 07 jQuery
jQuery AJAX 方法success()后台传来的4种数据详解
Aug 08 jQuery
jQuery解析json格式数据示例
Sep 01 jQuery
jQuery常见的遍历DOM操作详解
Sep 05 jQuery
jquery.param()实现数组或对象的序列化方法
Oct 08 jQuery
jQuery操作事件完整实例分析
Jan 10 jQuery
jquery传参及获取方式(两种方式)
Feb 13 jQuery
jQuery实现鼠标拖拽登录框移动效果
Sep 13 #jQuery
jQuery实现简单全选框
Sep 13 #jQuery
jQuery+ajax实现用户登录验证
Sep 13 #jQuery
jquery实现简易验证插件封装
Sep 13 #jQuery
jQuery实现朋友圈查看图片
Sep 11 #jQuery
jQuery实现日历效果
Sep 11 #jQuery
jquery实现简单每周轮换的日历
Sep 10 #jQuery
You might like
实现dedecms全站URL静态化改造的代码
2007/03/29 PHP
php中url传递中文字符,特殊危险字符的解决方法
2013/08/17 PHP
php5.4以上版本GBK编码下htmlspecialchars输出为空问题解决方法汇总
2015/04/03 PHP
php通过排列组合实现1到9数字相加都等于20的方法
2015/08/03 PHP
php给图片添加文字水印方法汇总
2015/08/27 PHP
PHP实现Unicode编码相互转换的方法示例
2020/11/17 PHP
解决出现SoapFault (looks like we got no XML document)的问题
2017/06/24 PHP
PHP实现的日历功能示例
2018/09/01 PHP
PHP __call()方法实现委托示例
2019/05/20 PHP
变量声明时命名与变量作为对象属性时命名的区别解析
2013/12/06 Javascript
JavaScript数组的栈方法与队列方法详解
2016/05/26 Javascript
利用Javascript实现BMI计算器
2016/08/16 Javascript
JavaScript变量类型以及变量作用域详解
2017/08/14 Javascript
React Native悬浮按钮组件的示例代码
2018/04/05 Javascript
AngularJs分页插件使用详解
2018/06/30 Javascript
vue过滤器用法实例分析
2019/03/15 Javascript
Vue内部渲染视图的方法
2019/09/02 Javascript
JS实现页面数据懒加载
2020/02/13 Javascript
Python 调用VC++的动态链接库(DLL)
2008/09/06 Python
python查询mysql中文乱码问题
2014/11/09 Python
Python 字典dict使用介绍
2014/11/30 Python
pyenv命令管理多个Python版本
2017/03/26 Python
python实现彩票系统
2020/06/28 Python
python 实现对文件夹中的图像连续重命名方法
2018/10/25 Python
OpenCV搞定腾讯滑块验证码的实现代码
2019/05/18 Python
对Django项目中的ORM映射与模糊查询的使用详解
2019/07/18 Python
python中的Elasticsearch操作汇总
2019/10/30 Python
Python logging日志库空间不足问题解决
2020/09/14 Python
python switch 实现多分支选择功能
2020/12/21 Python
钉钉企业内部H5微应用开发详解
2020/05/12 HTML / CSS
法国春天百货官网:Printemps.com
2020/06/29 全球购物
迟到检讨书1000字
2014/01/15 职场文书
报纸媒体创意广告词
2014/03/17 职场文书
在酒桌上的敬酒词
2015/08/12 职场文书
私人贷款担保书该怎么写呢?
2019/07/02 职场文书
Anaconda安装pytorch及配置PyCharm 2021环境
2021/06/04 Python