




已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
利用jQuery和CSS实现环形进度条最近项目里遇到一个有意思的效果,那就是圆形进度条,类似于这样的:实现类似这样的效果方法很多。我主要想了2个解决方案,都是通过jQuery和CSS实现的,下面就一一道来:方法一:jQuery + CSS3实现原理原理非常的简单,在这个方案中,最主要使用了CSS3的transform中的rotate和CSS3的clip两个属性。用他们来实现半圆和旋转效果。半环的实现先来看其结构。HTML 0%结构非常简单。这样的结构,大家一看就清楚。CSS.pie_right width:200px; height:200px; position: absolute; top: 0; left: 0; background:#0cc;.right width:200px; height:200px; background:#00aacc; border-radius: 50%; position: absolute; top: 0; left: 0;.pie_right, .right clip:rect(0,auto,auto,100px);.mask width: 150px; height: 150px; border-radius: 50%; left: 25px; top: 25px; background: #FFF; position: absolute; text-align: center; line-height: 150px; font-size: 20px; background: #0cc; /* mask 是不需要剪切的,此处只是为了让大家看到效果*/ clip:rect(0,auto,auto,75px); 实现半圆还是挺简单的,利用border-radius做出圆角,然后利用clip做出剪切效果,(clip使用方法,详见站内介绍),mask的部分是为了遮挡外面的容器,致使在视觉上产生圆环的效果:旋转的话,那更容易实现了,就是在CSS的right中加入(我没做浏览器兼容代码,请大家自行加入):.right transform: rotate(30deg);这样就可以看到一个半弧旋转的效果了。整环的实现同样道理,拼接左半边圆环,为了让我们html结构更易懂以后写js更简便,我对结构做了一下改造,并作了效果优化:HTML 0%CSS.circle width: 200px; height: 200px; position: absolute; border-radius: 50%; background: #0cc;.pie_left, .pie_right width: 200px; height: 200px; position: absolute; top: 0;left: 0;.left, .right display: block; width:200px; height:200px; background:#00aacc; border-radius: 50%; position: absolute; top: 0; left: 0; transform: rotate(30deg);.pie_right, .right clip:rect(0,auto,auto,100px);.pie_left, .left clip:rect(0,100px,auto,0);.mask width: 150px; height: 150px; border-radius: 50%; left: 25px; top: 25px; background: #FFF; position: absolute; text-align: center; line-height: 150px; font-size: 16px;效果如下:圆环最终效果Ok了,基本上我们的圆环已经实现完成了,下面是加入JS效果。首先,我们需要考虑的是,圆环的转动幅度大小,是由圆环里面数字的百分比决定的,从0%-100%,那么圆弧被分成了每份3.6;而在180,也就是50%进度之前,左侧的半弧是不动的,当超过50%,左边的半弧才会有转动显示。那么,原理明确之后,其jQuery代码如下(删除CSS中的旋转效果,在JS里重写):$(function() $(.circle).each(function(index, el) var num = $(this).find(span).text() * 3.6; if (num=180) $(this).find(.right).css(transform, rotate( + num + deg); else $(this).find(.right).css(transform, rotate(180deg); $(this).find(.left).css(transform, rotate( + (num - 180) + deg); ; ););则,改变mask里面的span 的数值,我们就会看到最终效果。这样我们只要从后台获取当前流程的进度值,传给span,那么我们页面上就能看到这样圆环的进度效果啦。jQuery + 图片实现原理这种方法相对来说就比较简单了,但是也是挺麻烦的一种。首先,我们需要一个非常冗长的一个图片图片的内容,就是每1旋转角度,就是一张图片100张例如:然后让容器为这个图片为背景,理由用background-position写100个类样式做背景偏移很累啊.进度每改变一下,就引用相对应的类。HTML我们类似于有这样的一个结构,当然这里面有很多个这样的结构: 0% 比如说我们的案例的中结构: 10% 20% 30% 50% 70% 90% 100% CSS样式是比较苦逼的事情,我们需要在每个位置修改他的background-position。也就是从0%100%,将会有100个:.progressbar text-align: center; line-height: 44px; width: 44px; display: block; background: url(progressbar.png); height: 44px; font-size: 14px; margin-left:60px;.progressbar-1 background-position: 0px 0px;.progressbar-2 background-position: -54px 0px;.progressbar-3 background-position: -108px 0px;.progressbar-4 background-position: -162px 0px;.progressbar-5 background-position: -216px 0px;.progressbar-6 background-position: -270px 0px;.progressbar-7 background-position: -324px 0px;.progressbar-8 background-position: -378px 0px;.progressbar-9 background-position: -432px 0px;.progressbar-10 background-position: -486px 0px;.progressbar-11 background-position: -540px 0px;.progressbar-12 background-position: -594px 0px;.progressbar-13 background-position: -648px 0px;.progressbar-14 background-position: -702px 0px;.progressbar-15 background-position: -756px 0px;.progressbar-16 background-position: -810px 0px;.progressbar-17 background-position: -864px 0px;.progressbar-18 background-position: -918px 0px;.progressbar-19 background-position: -972px 0px;.progressbar-20 background-position: -1026px 0px;.progressbar-21 background-position: -1080px 0px;.progressbar-22 background-position: -1134px 0px;.progressbar-23 background-position: -1188px 0px;.progressbar-24 background-position: -1242px 0px;.progressbar-25 background-position: -1296px 0px;.progressbar-26 background-position: -1350px 0px;.progressbar-27 background-position: -1404px 0px;.progressbar-28 background-position: -1458px 0px;.progressbar-29 background-position: -1512px 0px;.progressbar-30 background-position: -1566px 0px;.progressbar-31 background-position: -1620px 0px;.progressbar-32 background-position: -1674px 0px;.progressbar-33 background-position: -1728px 0px;.progressbar-34 background-position: -1782px 0px;.progressbar-35 background-position: -1836px 0px;.progressbar-36 background-position: -1890px 0px;.progressbar-37 background-position: -1944px 0px;.progressbar-38 background-position: -1998px 0px;.progressbar-39 background-position: -2052px 0px;.progressbar-40 background-position: -2106px 0px;.progressbar-41 background-position: -2160px 0px;.progressbar-42 background-position: -2214px 0px;.progressbar-43 background-position: -2268px 0px;.progressbar-44 background-position: -2322px 0px;.progressbar-45 background-position: -2376px 0px;.progressbar-46 background-position: -2430px 0px;.progressbar-47 background-position: -2484px 0px;.progressbar-48 background-position: -2538px 0px;.progressbar-49 background-position: -2592px 0px;.progressbar-50 background-position: -2700px 0px;.progressbar-51 background-position: -2754px 0px;.progressbar-52 background-position: -2808px 0px;.progressbar-53 background-position: -2862px 0px;.progressbar-54 background-position: -2916px 0px;.progressbar-55 background-position: -2970px 0px;.progressbar-56 background-position: -3024px 0px;.progressbar-57 background-position: -3078px 0px;.progressbar-58 background-position: -3132px 0px;.progressbar-59 background-position: -3186px 0px;.progressbar-60 background-position: -3240px 0px;.progressbar-61 background-position: -3294px 0px;.progressbar-62 background-position: -3348px 0px;.progressbar-63 background-position: -3402px 0px;.progressbar-64 background-position: -3456px 0px;.progressbar-65 background-position: -3510px 0px;.progressbar-66 background-position: -3564px 0px;.progressbar-67 background-position: -3618px 0px;.progressbar-68 background-position: -3672px 0px;.progressbar-69 background-position: -3726px 0px;.progressbar-70 background-position: -3780px 0px;.progressbar-71 background-position: -3834px 0px;.progressbar-72 background-position: -3888px 0px;.progressbar-73 background-position: -3942px 0px;.progressbar-74 background-position: -3996px 0px;.progressbar-75 background-position: -4050px 0px;.progressbar-76 background-position: -4104px 0px;.progressbar-77 background-position: -4158px 0px;.progressbar-78 background-position: -4212px 0px;.progressbar-79 background-position: -4266px 0px;.progressbar-80 background-position: -4320px 0px;.progressbar-81 background-position: -4376px 0px;.progressbar-82 background-position: -4428px 0px;.progressbar-83 background-position: -4482px 0px;.progressbar-84 background-position: -4536px 0px;.progressbar-85 background-position: -4590px 0px;.progressbar-86 background-position: -4644px 0px;.progressbar-87 background-position: -4698px 0px;.progressbar-88 background-position: -4752px 0px;.progressbar-89 background-position: -4806px 0px;.progressbar-90 background-position: -486
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- Brand KPIs for online betting:Betfair in Brazil-英文培训课件2025.5
- 2025年(完整版)小升初数学公式
- AI大模型赋能区域医疗数字化医联体建设方案
- 华为公司干部管理与培养(一)7P
- 山东省德州市武城县五校联考2024-2025学年八年级下学期第二次月考数学试卷(答案不完整)
- 先进先出试题及答案
- 武汉理化试题及答案详解
- 广东省东莞市光正实验学校2024-2025学年高一下学期期中考试英语试卷(解析版)
- 2025年广西中考数学第一次模拟试卷(无答案)
- 湖北省恩施土家族苗族自治州2024-2025学年高一下学期期末考试语文试卷(含答案)
- 2025年全国国家版图知识竞赛(中小学组)题库
- 蔬菜净菜车间管理制度
- 2025年高考化学考点复习之有机合成(解答大题)
- 企业国际化经营中的人力资源管理
- 2025餐厅服务员劳动合同范本
- 竣工预验收自评报告
- 2025年中国石油化工行业市场发展前景及发展趋势与投资战略研究报告
- 毕业设计(论文)-手推式草坪修剪机设计
- 毕业季快闪抖音演示模板
- DB62-T 5072-2024 公路固废基胶凝材料稳定碎石混合料 设计与施工规范
- 《文化和旅游领域重大事故隐患判定标准》知识培训
评论
0/150
提交评论