html5实现进度条功能效果非常和谐
1. [图片] html5.jpg
2. [代码][HTML]代码
<script type="text/javascript">
var i = 0;
var res = 0;
var context = null;
var total_width = 300;
var total_height = 34;
var initial_x = 20;
var initial_y = 20;
var radius = total_height/2;
window.onload = function() {
var elem = document.getElementById('myCanvas');
if (!elem || !elem.getContext) {
return;
}
context = elem.getContext('2d');
if (!context) {
return;
}
// set font
context.font = "16px Verdana";
// Blue gradient for progress bar
var progress_lingrad = context.createLinearGradient(0,initial_y+total_height,0,0);
progress_lingrad.addColorStop(0, '#4DA4F3');
progress_lingrad.addColorStop(0.4, '#ADD9FF');
progress_lingrad.addColorStop(1, '#9ED1FF');
context.fillStyle = progress_lingrad;
//draw();
res = setInterval(draw, 30);
}
function draw() {
i+=1;
// Clear everything before drawing
context.clearRect(initial_x-5,initial_y-5,total_width+15,total_height+15);
progressLayerRect(context, initial_x, initial_y, total_width, total_height, radius);
progressBarRect(context, initial_x, initial_y, i, total_height, radius, total_width);
progressText(context, initial_x, initial_y, i, total_height, radius, total_width );
if (i>=total_width) {
clearInterval(res);
}
}
/**
* Draws a rounded rectangle.
* @param {CanvasContext} ctx
* @param {Number} x The top left x coordinate
* @param {Number} y The top left y coordinate
* @param {Number} width The width of the rectangle
* @param {Number} height The height of the rectangle
* @param {Number} radius The corner radius;
*/
function roundRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.arc(x+width-radius, y+radius, radius, -Math.PI/2, Math.PI/2, false);
ctx.lineTo(x + radius, y + height);
ctx.arc(x+radius, y+radius, radius, Math.PI/2, 3*Math.PI/2, false);
ctx.closePath();http://www.huiyi8.com/hunsha/chuangyi/
ctx.fill();创意婚纱照片
}
/**
* Draws a rounded rectangle.
* @param {CanvasContext} ctx
* @param {Number} x The top left x coordinate
* @param {Number} y The top left y coordinate
* @param {Number} width The width of the rectangle
* @param {Number} height The height of the rectangle
* @param {Number} radius The corner radius;
*/
function roundInsetRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
// Draw huge anti-clockwise box
ctx.moveTo(1000, 1000);
ctx.lineTo(1000, -1000);
ctx.lineTo(-1000, -1000);
ctx.lineTo(-1000, 1000);
ctx.lineTo(1000, 1000);
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.arc(x+width-radius, y+radius, radius, -Math.PI/2, Math.PI/2, false);
ctx.lineTo(x + radius, y + height);
ctx.arc(x+radius, y+radius, radius, Math.PI/2, 3*Math.PI/2, false);
ctx.closePath();
ctx.fill();
}
function progressLayerRect(ctx, x, y, width, height, radius) {
ctx.save();
// Set shadows to make some depth
ctx.shadowOffsetX = 2;
ctx.shadowOffsetY = 2;
ctx.shadowBlur = 5;
ctx.shadowColor = '#666';
// Create initial grey layer
ctx.fillStyle = 'rgba(189,189,189,1)';
roundRect(ctx, x, y, width, height, radius);
// Overlay with gradient
ctx.shadowColor = 'rgba(0,0,0,0)'
var lingrad = ctx.createLinearGradient(0,y+height,0,0);
lingrad.addColorStop(0, 'rgba(255,255,255, 0.1)');
lingrad.addColorStop(0.4, 'rgba(255,255,255, 0.7)');
lingrad.addColorStop(1, 'rgba(255,255,255,0.4)');
ctx.fillStyle = lingrad;
roundRect(ctx, x, y, width, height, radius);
ctx.fillStyle = 'white';
//roundInsetRect(ctx, x, y, width, height, radius);
ctx.restore();
}
/**
* Draws a half-rounded progress bar to properly fill rounded under-layer
* @param {CanvasContext} ctx
* @param {Number} x The top left x coordinate
* @param {Number} y The top left y coordinate
* @param {Number} width The width of the bar
* @param {Number} height The height of the bar
* @param {Number} radius The corner radius;
* @param {Number} max The under-layer total width;
*/
function progressBarRect(ctx, x, y, width, height, radius, max) {
// var to store offset for proper filling when inside rounded area
var offset = 0;
ctx.beginPath();
if (width<radius) {
offset = radius - Math.sqrt(Math.pow(radius,2)-Math.pow((radius-width),2));
ctx.moveTo(x + width, y+offset);
ctx.lineTo(x + width, y+height-offset);
ctx.arc(x + radius, y + radius, radius, Math.PI - Math.acos((radius - width) / radius), Math.PI + Math.acos((radius - width) / radius), false);
}
else if (width+radius>max) {
offset = radius - Math.sqrt(Math.pow(radius,2)-Math.pow((radius - (max-width)),2));
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width, y);
ctx.arc(x+max-radius, y + radius, radius, -Math.PI/2, -Math.acos((radius - (max-width)) / radius), false);
ctx.lineTo(x + width, y+height-offset);
ctx.arc(x+max-radius, y + radius, radius, Math.acos((radius - (max-width)) / radius), Math.PI/2, false);
ctx.lineTo(x + radius, y + height);
ctx.arc(x+radius, y+radius, radius, Math.PI/2, 3*Math.PI/2, false);
}
else {
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width, y);
ctx.lineTo(x + width, y + height);
ctx.lineTo(x + radius, y + height);
ctx.arc(x+radius, y+radius, radius, Math.PI/2, 3*Math.PI/2, false);
}
ctx.closePath();
ctx.fill();
// draw progress bar right border shadow
if (width<max-1) {
ctx.save();
ctx.shadowOffsetX = 1;
ctx.shadowBlur = 1;
ctx.shadowColor = '#666';
if (width+radius>max)
offset = offset+1;
ctx.fillRect(x+width,y+offset,1,total_height-offset*2);
ctx.restore();
}
}
/**
* Draws properly-positioned progress bar percent text
* @param {CanvasContext} ctx
* @param {Number} x The top left x coordinate
* @param {Number} y The top left y coordinate
* @param {Number} width The width of the bar
* @param {Number} height The height of the bar
* @param {Number} radius The corner radius;
* @param {Number} max The under-layer total width;
*/
function progressText(ctx, x, y, width, height, radius, max) {
ctx.save();
ctx.fillStyle = 'white';
var text = Math.floor(width/max*100)+"%";
var text_width = ctx.measureText(text).width;
var text_x = x+width-text_width-radius/2;
if (width<=radius+text_width) {
text_x = x+radius/2;
}
ctx.fillText(text, text_x, y+22);
ctx.restore();
}
</script>
转载于:https://www.cnblogs.com/xkzy/p/3946576.html
html5实现进度条功能效果非常和谐相关推荐
- html canvas直线进度条,js+HTML5 canvas 实现简单的加载条(进度条)功能示例
本文实例讲述了js+HTML5 canvas 实现简单的加载条(进度条)功能.分享给大家供大家参考,具体如下: www.jb51.net canvas实现加载条动画 /* * 获取canvas, ca ...
- 如何用HTML语言设计进度条,html5代码如何实现进度条功能?(示例)
本篇文章主要介绍html5代码如何实现进度条功能,希望对大家有所帮助. html5代码实现进度条功能具体代码示例如下:/*实现进度条的功能*/ 下载进度: /*js代码*/ var pg=docume ...
- html5倒计时效果,html5+css3进度条倒计时动画特效代码【推荐】
html5+css3进度条倒计时动画特效这个作品在今天上网找网络资源的时候无意中发现的,看到效果非常棒并且很实用,就第一时间把它整理出来与大家分享了,主要用到了html5.javascript和css ...
- pdf html5 阅读进度,HTML5的进度条progress元素
原标题:HTML5的进度条progress元素 progress元素属于HTML5新元素,指进度条.IE10+以及其他靠谱浏览器都支持. 体验一下效果: 在html里写入 查看浏览器效果:不同浏览器下 ...
- 9款极具创意的HTML5/CSS3进度条动画
今天我们要分享9款极具创意的HTML5/CSS3进度条动画,这些进度条也许可以帮你增强用户交互和提高用户体验,喜欢的朋友就收藏了吧. 1.HTML5/CSS3图片加载进度条 可切换多主题 今天要分享的 ...
- html进度条倒计时代码,html5+css3进度条倒计时动画特效代码【推荐】_html5教程技巧...
html5+css3进度条倒计时动画特效这个作品在今天上网找网络资源的时候无意中发现的,看到效果非常棒并且很实用,就第一时间把它整理出来与大家分享了,主要用到了html5.javascript和css ...
- springboot:实现文件上传下载实时进度条功能【附带源码】
0. 引言 记得刚入行的时候,做了一个文件上传的功能,因为上传时间较久,为了用户友好性,想要添加一个实时进度条,显示进度.奈何当时技术有限,查了许久也没用找到解决方案,最后不了了之. 近来偶然想到这个 ...
- h5动画 php,HTML_多视角3D逼真HTML5水波动画 ,html5+css3进度条倒计时动画特效 - phpStudy...
多视角3D逼真HTML5水波动画 html5+css3进度条倒计时动画特效这个作品在今天上网找网络资源的时候无意中发现的,看到效果非常棒并且很实用,就第一时间把它整理出来与大家分享了,主要用到了htm ...
- html进度条实现原理,HTML5 progress进度条详解
HTML5 progress 元素简介 progress是HTML5的一个新元素,表示定义一个进度条,用途很广泛,可以用在文件上传的进度显示,文件下载的进度显示,也可以作为一种loading的加载状态 ...
最新文章
- 激光+视觉+IMU+GPS如何做融合?
- MATLAB应用实战系列(七十六)-【仿真应用】卡尔曼滤波在雷达目标跟踪中的应用仿真(附matlab代码)
- 【干货】如何引导免费用户成为付费用户
- 5ic计算机考试考卷读取错误,最新计算机一级试题第五套
- matlab最小错误率决策,利用MATLAB实现最小错误率贝叶斯判别
- ORA-01855: AM/A.M. or PM/P.M. required问题排查与解析
- WinForm窗体PropertyGrid控件的使用
- linux的idle命令,DBA 常用Linux命令
- 安卓开发之软件维护的策略
- Kubernetes证书相关(CFSSL)
- php baseconvert,mb_convert_encoding
- VC6 程序 在VS2019或其他高版本上编译运行
- Python实现QQ定时回复(附源码exe)
- 关于多极充磁磁环表面磁场分布的研发历程GM900系列表磁分布测量仪
- Java中final、finally、finalize的简单区别,中等区别,详细区别(Lawliet 修改+注释版)
- 学会超短怎么做,才能更好地穿越牛市和熊市
- PWM信号通过功率三极管控制电机,PWM波形失真问题。
- 如何录制微课?教师必看
- ySQL字符串函数:字符串截取
- WWCD 2018:通知分组的使用
热门文章
- A multi-faceted language for the Java platform
- Android小项目源码汇总
- httpHandlers和httpModules接口介绍 (7)
- 浅谈iPhone和iPad开发中的图标设置
- 使用计算机加密码,给正使用的电脑设置密码
- 美国计算机科学专业申请要求,美国计算机科学专业好申请吗?申请要求高不高...
- shell 中常用到的基础命令
- 阿里云低延时直播RTS能力升级,让直播推流效果更佳
- 阿里巴巴DevOps实践指南 | 数字化转型下,DevOps的根本目标是什么?
- 揭秘!双11万亿流量下的分布式缓存系统 Tair