利用css3动画和border来实现圆形进度条_html/css_WEB-ITnose
最近在学习前端的一些知识,发现border的功能十分强大啊!
首先来看看demo
就是这么一个圆形的进度条,在文本框中输入0-100的数值下面的进度条相应的转到多少
这个主要是利用border,旋转和css动画来实现的,主要思想是利用两个div来互相遮挡border形成的一个只有半圈有颜色的圆形,再利用旋转div的角度来调整显示
上代码:
html+css+js(这里引入了jquery)
<!DOCTYPE html><html lang="en"> <head> <meta charset="utf-8"> <meta name="KeyWord" content="cicle,learning"> <meta name="description" content="cicle-learning"> <meta name="Author" content="alsy"> <title>圆形进度条</title> <!-- style-start --> <!-- style-end --> <style> .content { width: 400px; height: 400px; margin: 10px auto 100px; } .content .input{ position: relative; margin: 40px auto; } .content .cicle { position: relative; margin: 100px auto; width: 100px; height: 100px; border-width: 20px; border-color: red; border-style: solid; border-radius: 50%; } .content .cicle .bar { position: absolute; width: 70px; height: 140px; overflow: hidden; } .content .cicle .bar-left { top: -20px; left: -20px; } .content .cicle .bar-left .bar-left-an{ position: absolute; z-index: 10; width: 100px; height: 100px; border-width: 20px; border-color: transparent transparent green green; border-style: solid; border-radius: 50%; transform: rotate(-135deg); } .content .cicle .bar-right { top: -20px; left: 50px; } .content .cicle .bar-right .bar-right-an { position: absolute; left: -70px; z-index: 20; width: 100px; height: 100px; border-width: 20px; border-color: green green transparent transparent; border-style: solid; border-radius: 50%; transform: rotate(-135deg); } .content .cicle .tx { position: absolute; width: 100px; height: 100px; line-height: 100px; text-align: center; font-size: 20px; font-weight: 800; color: green; } </style> </head> <body> <div class="content"> <div class="input"> <label>进度条:</label><input type="text" id="inp"/> </div> <div class="cicle"> <div class="bar bar-left"> <div class="bar-left-an"></div> </div> <div class="bar bar-right"> <div class="bar-right-an"></div> </div> <div class="tx">0%</div> </div> </div> <!-- import-js --> <script type="text/javascript" src="js/jquery.js"></script> <!-- import-my-js --> <script type="text/javascript"> $(document).ready(function() { var cicle = cle = function() { var oTx = $(".tx"); var cicleTransform = function(num, old_num) { var b_l_a = $(".bar-left-an"); var b_r_a = $(".bar-right-an"); var c_num = num; if(c_num > 50) { b_r_a.css({ "transform": "rotate(45deg)", "transition": "transform 1s linear" }); setTimeout(function() { b_l_a.css({ "transform": "rotate(" + (((c_num-50)/100*360)-135) + "deg)", "transition": "transform 1s linear" }); },1000); } else { if(old_num > 50) { setTimeout(function() { b_r_a.css({ "transform": "rotate(" + ((c_num/100*360)-135) + "deg)", "transition": "transform 1s linear" }); },1000); b_l_a.css({ "transform": "rotate(-135deg)", "transition": "transform 1s linear" }); } else { b_r_a.css({ "transform": "rotate(" + ((c_num/100*360)-135) + "deg)", "transition": "transform 1s linear" }); } } } var setnum = function(num) { oTx.text(num + "%"); } var getnum = function() { return parseInt(oTx.text()); } var inputB = function() { $("#inp").blur(function() { var num = parseInt($.trim( $(this).val() )); if(num>=0 && num <= 100){ cicleTransform(num, getnum()); setnum(num); }else{ alert("输入100以内的数值!"); } }); } return { init: function() { inputB(); } } }(); cicle.init(); }); </script> </body></html>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...
