网页变幻云+canvas时钟
来源:互联网 发布:知乎女神王 出书 编辑:程序博客网 时间:2024/05/17 02:34
//本HTML代码主要是制作一个变换云背景,利用了三张透明背景图进行穿插,
//加上蓝黑背景色营造出一种变换的效果。中间div穿插了一个时钟,是利用
//canvas画出来的,可以获取当前时间,加上背景的变幻莫测,整体别具一格。
<!DOCTYPE html><html><head><meta charset="utf-8" /><title></title><style type="text/css">#mycanvas{position: absolute;/*z-index: 1;*/left: 50%;margin-left: -250px;}.bg-color {width: 100%;height: 500px;position: relative;background-color: #007FD5;animation:change-color 50s ease infinite;}@keyframes change-color{0% {background-color:#007fd5;}50% {background-color:#000000;}100% {background-color:#007fd5;}}.cloud-one{width: 300%;height:500px ;background-image: url(img/cloud_one.png);position: absolute;top: 0;left: 0;animation: cloudmoving1 70s linear infinite;}@keyframes cloudmoving1{from{left: 0px;}to{left: -200%;}}.cloud-two{width: 300%;height:500px ;background-image: url(img/cloud_two.png);position: absolute;top: 0;left: 0;animation: cloudmoving2 100s linear infinite;}@keyframes cloudmoving2{from{left: 0px;}to{left: -200%;}.cloud-three{width: 300%;height:500px ;background-image: url(img/cloud_three.png);position: absolute;top: 0;left: 0;animation: cloudmoving3 120s linear infinite;}@keyframes cloudmoving3{from{left: 0px;}to{left: -200%;}</style></head><body><!-- 作者:offline 时间:2017-08-12 描述:canvas:html5新增的画布对象,可以在其中绘制任何的图像,以及线条效果,包括图片 canvas的尺寸应该通过属性进行设置,而不是使用样式进行设置! --><div class="bg-color"><canvas id="mycanvas" width="500px" height="500px">您的浏览器太low了,实现不了!</canvas><script type="text/javascript">//获取画布对象var mycanvas = document.getElementById('mycanvas');//获取一个2d绘图环境(拿到一支画笔)var ctx = mycanvas.getContext('2d');function draw(){//获取系统时间var nowTime = new Date();var hours = nowTime.getHours();var minutes = nowTime.getMinutes();var seconds = nowTime.getSeconds();//console.info(hours+":"+minutes+":"+seconds); //防止小时数超过12 hours = hours>12?hours-12:hours; //精准的设置小时位置 hours = hours+minutes/60; //清除画布(防止覆盖效果) ctx.clearRect(0,0,500,500);//初始化画笔的样式ctx.lineWidth = 2; //设置线条的宽度ctx.strokeStyle = '#fff'; //设置线条的颜色ctx.beginPath(); //开始画图路径//设置一个圆形路径ctx.arc(250,250,150,0,360,false);//绘制图形ctx.stroke();ctx.closePath(); //结束画图路径//绘制刻度(时刻度)for(var i=0;i<12;i++){ctx.beginPath();ctx.lineWidth=8;//保存当前绘图环境ctx.save();//重置绘制的起始位置(将圆心位置重置为0.0)ctx.translate(250,250);//转换画布的用户坐标系统//旋转画布到一定的弧度 弧度=角度*PI/180ctx.rotate(i*30*Math.PI/180);//设置绘制线条的起始位置ctx.moveTo(0,140);//设置线条的结束位置ctx.lineTo(0,150);//绘制路劲ctx.stroke();//还原初始的绘图环境ctx.restore();ctx.closePath();}//绘制刻度(分刻度)for(var i=0;i<60;i++){ctx.beginPath();ctx.lineWidth=3;//保存当前绘图环境ctx.save();//重置绘制的起始位置(将圆心位置重置为0.0)ctx.translate(250,250);//转换画布的用户坐标系统//旋转画布到一定的弧度 弧度=角度*PI/180ctx.rotate(i*6*Math.PI/180);//设置绘制线条的起始位置ctx.moveTo(0,140);//设置线条的结束位置ctx.lineTo(0,148);//绘制路劲ctx.stroke();//还原初始的绘图环境ctx.restore();ctx.closePath();}//绘制时针ctx.beginPath();ctx.lineWidth=5;//保存当前绘图环境ctx.save();//重置绘制的起始位置(将圆心位置重置为0.0)ctx.translate(250,250);//转换画布的用户坐标系统//旋转画布到一定的弧度 弧度=角度*PI/180ctx.rotate(hours*30*Math.PI/180);//设置绘制线条的起始位置ctx.moveTo(0,10);//设置线条的结束位置ctx.lineTo(0,-100);//绘制路劲ctx.stroke();//还原初始的绘图环境ctx.restore();ctx.closePath();//绘制分针ctx.beginPath();ctx.lineWidth=3;//保存当前绘图环境ctx.save();//重置绘制的起始位置(将圆心位置重置为0.0)ctx.translate(250,250);//转换画布的用户坐标系统//旋转画布到一定的弧度 弧度=角度*PI/180ctx.rotate(minutes*6*Math.PI/180);//设置绘制线条的起始位置ctx.moveTo(0,10);//设置线条的结束位置ctx.lineTo(0,-120);//绘制路劲ctx.stroke();//还原初始的绘图环境ctx.restore();ctx.closePath();//绘制秒针ctx.beginPath();ctx.lineWidth=1;ctx.strokeStyle='#f00';//保存当前绘图环境ctx.save();//重置绘制的起始位置(将圆心位置重置为0.0)ctx.translate(250,250);//转换画布的用户坐标系统//旋转画布到一定的弧度 弧度=角度*PI/180ctx.rotate(seconds*6*Math.PI/180);//设置绘制线条的起始位置ctx.moveTo(0,10);//设置线条的结束位置ctx.lineTo(0,-126);//绘制路劲ctx.stroke();//还原初始的绘图环境ctx.restore();ctx.closePath();}setInterval(draw,1000);</script><div class="cloud-one"></div><div class="cloud-two"></div><div class="cloud-three"></div></div></body></html>
阅读全文
0 0
- 网页变幻云+canvas时钟
- Canvas时钟
- canvas时钟
- canvas时钟
- Canvas时钟
- Canvas 时钟
- Canvas时钟
- Canvas--时钟
- Canvas时钟
- Canvas时钟
- canvas--时钟
- HTML5特性 > Canvas >变幻的色彩
- 前端(canvas)圆形网页时钟实现,源码
- 用canvas标签实现网页H5动态时钟
- 网页时钟
- 网页时钟
- 网页时钟
- canvas实现时钟效果
- 数据、数据元素、数据对象、数据结构的定义
- AtCoder Beginner Contest 070 D
- 百度之星初赛(B)--Factory---虚树/比格思茅/LCA
- 浅谈Java SE、Java EE、Java ME三者的区别
- 解决Win10成功安装pycrypto后依旧报错找不到
- 网页变幻云+canvas时钟
- 从能级的角度来看半导体的掺杂
- 由二叉树的前序序列和中序序列构建二叉树
- MAC上为Android Studio集成Genymotion模拟器
- web无插件播放RTSP摄像机方案,拒绝插件,拥抱H5!
- Java关于短路与&&的巧妙运用
- win10 大文件 安卓android studio修改 汉化
- 关于mysql常见的问题(一些常见问题的解决方案)
- Spring Cloud学习系列第三章:云计算断路器模式实现库Hystrix