PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
|
积分获取
|
给我留言
|
tag标签
首页
开发编程
PHP教程
ASP.NET教程
Jquery教程
Unity3D教程
JavaScript教程
HTML+CSS
ThinkPhp教程
Smarty教程
正则表达式
编程杂谈
HTML5+CSS3教程
HBuilderX教程
AngularJS教程
Laravel教程
iOS开发教程
Java教程
小程序开发
提供网页设计教程和后台编程技术
CMS教程
phpcms教程
dedecms教程
wordpress教程
ecshop教程
帝国cms教程
discuz教程
齐博cms教程
ShopNc教程
提供主流cms教程
数据库
MySQL教程
SQL Server教程
NoSql数据库
提供数据库教程和设计
JS特效
HTML5+CSS3特效
焦点图
菜单导航
广告特效
对联广告
在线客服
相册特效
图片特效
悬浮漂浮
滚动特效
Tab选项卡
瀑布流
手机js特效
弹出层(框)
日期时间
网页模板
其它特效
提供各种常见网页js代码
网页特效
HTML5+CSS3
鼠标特效
文字特效
导航菜单
表格图层
Tab选项卡
图片特效
时间日期
网站常用
提供常用的JS特效代码及在线演示
Jquery插件
jQuery日期时间
jQuery弹出层
jQuery筛选排序
jQuery滚动插件
jQuery工具提示
jQuery音频视频
jQuery选项卡
jQuery图片裁剪
jQuery常用插件
jQuery导航菜单
提供jQuery插件教程及插件下载
服务器
Linux教程
Web服务器
提供服务器常见问题及教程
站长学院
seo技巧
建站经验
网络营销
站长资讯
好文分享
网络推广
互联网资讯
提供站长技术、站长资讯等内容
工具&手册
Base64编码加密
正则测试工具
Css压缩/格式化
jQuery手册
md5加密
CSS3
帝国cms开发手册
DEDE5.7使用手册
配色词典
C语言库
提供常用开发手册和开发工具
全站搜索
搜索
关键字:
瀑布流
仿麦包包
拖动图片
nginx
对象编程
$GLOBALS
select
缩略图
您现在的位置:
首页
>
网页特效
>
HTML5+CSS3
> 正文
canvas 多彩动画时钟
作者:admin
来源:网络
浏览:
次
时间:2020-10-24 21:11:49
我要评论
分享到
内容介绍
html5 canvas 多彩动画时钟
<html> <head> <meta charset="utf-8"> <style> *{ padding:0px; margin: 0px; } #canvas1{ border:0px solid grey; margin:0 auto; display:block; } #ctrl_box{ position: absolute; padding: 5px; height: 60px; width: 360px; margin:0 auto; left:50%; top:15px; background-color: rgba(111,111,111,0.4); border-radius: 10px; } #ctrl_box> span{ font-family: arial; display: inline-block; position: relative; margin: 10px; padding: 10px; border-radius: 8px; } #ctrl_box> span.hide{ color:white; background-color: rgba(198,129,242,0.4); } #ctrl_box> span.show{ color:#e7734f; background-color: rgba(255,255,0,4); } #ctrl_box> span.bg{ width: 64px; color:white; text-align: center; background-color: rgba(115,255,222,0.4); -webkit-transition: width 0.3s; -o-transition: width 0.3s; -moz-transition: width 0.3s; } #ctrl_box> span:hover{ cursor: pointer; } #box{ position: relative; margin:0 auto; top:80px; border: 1px black solid } #bgPtts{ position: absolute; left:0px; top:0px; opacity: 0.8; border:white solid 0px; border-radius: 8px; transition: 0.4s; transition-delay:0.32s; background-color:white; transform: scale(0,1); } #bgPtts>div{ height:35px; width: 80px; overflow: hidden; border:white solid 2px; border-radius: 8px; } #bgPtts div:hover{ cursor: pointer; border:purple solid 2px; } #bgPtts>div.selected{ border:yellow solid 2px; } #bgPtts span{ display: inline-block; width: 100%; height: 100%; } #bgPtts span.grey{ background-color: grey; } #bgPtts span.green{ background-color: green; } #grey{ background-color: #eee; } </style> </head>> <body> <!-- <p class="scroll-wrap">111</p>--> <!-- <p id="demo"></p> --> <div id="box"> <canvas id="canvas1" style=""></canvas> <div id="ctrl_box"> <span id="fullYear" class="hide">显示年份</span> <span id="date" class="hide">显示日期</span> <span id="bg" class="bg"> 背 景 <div id="bgPtts"> <div id="" class="selected"><img src="http://img1.ph.126.net/5z5lEMFbjVW4k4Qs1Ms5vw==/882705526964687950.jpg" id="pic2" /></div> <div id="" class=""><img src="http://img1.ph.126.net/oB-WUnsGl-Zksda3jASTig==/6631529560584389488.jpg" numColor="#eee"/></div> </div> </span> </div> </div> <script type="text/javascript" src="digit.js"></script> <script> window.onload=function () { var tShowClock; var canvas1=document.getElementById("canvas1"); var ebox=document.getElementById("box"); var efullYear=document.getElementById("fullYear"); var edate=document.getElementById("date"); var ebg=document.getElementById("bg"); var ebgPtts=document.getElementById("bgPtts"); var iRadius=6,iGap=1; var iVertexX=100,iVertexY=100; var iShowLen=8; var sTimePrev=""; var aBalls=[]; var aColors=["cyan","yellow","#7FFF00","#234","#567","LightCyan","Magenta","DarkViolet","Fuchsia","GreenYellow "]; var bgcolors=["grey","green"]; var context=canvas1.getContext('2d'); var cBgColor="#eee",bBgPic; var pic1=document.getElementById('pic2'); var ebgPtts_img=ebgPtts.getElementsByTagName("img"); // console.log(ebgPtts_img[1]) var ebgPtts_colors=ebgPtts.getElementsByTagName("span"); // console.log(ebgPtts_img[1]) var pat; //存放背景 for (i=0;i<=bgcolors.length-1;i++){ var newNode=document.createElement("div"); newNode.className=""; var newSpan=document.createElement("span"); newSpan.className=bgcolors[i]; newNode.appendChild(newSpan) ebgPtts.appendChild(newNode) //snewNode.append() } for (var i = ebgPtts_img.length - 1; i >= 0; i--) { ebgPtts_img[i].onclick=function(e){ pat=context.createPattern(this,"repeat"); //console.log(this.parentNode) fResetBgBorder(ebgPtts_img) fResetBgBorder(ebgPtts_colors) this.parentNode.className="selected"; } } for (var i = ebgPtts_colors.length - 1; i >= 0; i--) { ebgPtts_colors[i].onclick=function(e){ pat=this.className; console.log(this.backgroundColor) console.log(this) //console.log(this.parentNode) fResetBgBorder(ebgPtts_colors) fResetBgBorder(ebgPtts_img) this.parentNode.className="selected"; } } pat=context.createPattern(ebgPtts_img[0],"repeat"); WINDOW_WIDTH=1024;WINDOW_HEIGHT=489; WINDOW_WIDTH=fSetWidth(canvas1,8,iRadius,iGap,ebox) edate.onclick=function(){ if(this.className=="hide"){ this.className="show" this.innerHTML="隐藏日期" iShowLen=14; }else if(this.className=="show"){ iShowLen=8; this.className="hide" efullYear.className="hide" this.innerHTML="显示日期" efullYear.innerHTML="显示年份" } WINDOW_WIDTH=fSetWidth(canvas1,iShowLen,iRadius,iGap,ebox) aBalls=[] } efullYear.onclick=function(){ if(this.className=="hide"){ this.className="show" edate.className="show" this.innerHTML="隐藏年份" edate.innerHTML="隐藏日期" iShowLen=19; }else if(this.className=="show"){ iShowLen=14; this.className="hide" this.innerHTML="显示年份" } WINDOW_WIDTH=fSetWidth(canvas1,iShowLen,iRadius,iGap,ebox) aBalls=[] } var timeRight,timeLeft; ebg.onmouseover=function(){ bgPtts.style.transform="scale(1,1)"; //clearTimeout(timeLeft); //var innerArrows=earrow.getElementsByTagName("div"); //fSetArrow(innerArrows,"right") //console.log(earrow) //timeRight=setTimeout(function(){fSetArrow(innerArrows,"left"); },300 ) //earrow.style.left=75+"px"; //this.style.width=150+"px"; ebg.onmouseout=function(){ //clearTimeout(timeRight); //fSetArrow(innerArrows,"left") // earrow.style.left=0+"px"; // this.style.width=100+"px"; bgPtts.style.transform="scale(0,1)"; //timeLeft=setTimeout(function(){fSetArrow(innerArrows,"right");},300) } } function fSetArrow(AaElem,AsClassName){ for (var i = AaElem.length - 1; i >= 0; i--) { AaElem[i].css(transitionDelay,"0.4s"); //console.log("changing to "+AsClassName) AaElem[i].className=AsClassName; //console.log("changing to "+AsClassName) } AaElem[i].style.transitionDelay="0s"; } function fResetBgBorder(AaElem){ for (var i = AaElem.length - 1; i >= 0; i--) { AaElem[i].parentNode.className=""; } } ebox.style.width=WINDOW_WIDTH+"px",ebox.style.height=WINDOW_HEIGHT+"px"; canvas1.width = WINDOW_WIDTH; canvas1.height = WINDOW_HEIGHT; //function fGetWidth() function fSetWidth(Actx,AStrLen,Ar,AGap,Acontainer){ var iNumBalls,iWidth; switch(AStrLen){ case 8: iNumBalls=6*7+2*4;iWidth=iNumBalls*2*(Ar+AGap) break; case 14: iNumBalls=10*7+4*4;iWidth=iNumBalls*2*(Ar+AGap) break; case 19: iNumBalls=14*7+5*4;iWidth=iNumBalls*2*(Ar+AGap) break; } iWidth=iVertexX*2+iWidth; Actx.width=iWidth;console.log(Actx.width) Acontainer.style.width=iWidth+"px"; //return iWidth; return iWidth; } function fGetTimeString(aLong){ var dNow= new Date(); var iH=fToTwo(dNow.getHours()); var iM=fToTwo(dNow.getMinutes()); var iS=fToTwo(dNow.getSeconds()); var iD=fToTwo(dNow.getDate()) var iMonth=fToTwo(dNow.getMonth()+1) var iY=dNow.getFullYear() var sNow=iY+"."+iMonth+"."+iD+" "+iH+":"+iM+":"+iS; return sNow.slice(19-aLong,19); }; function fToTwo(aNum){ return aNum>=10?aNum:"0"+aNum; }; function fNumDraw(aNum,aRadius,aGap,aVertexX,aVertexY){ var i=0,j=0,iX=0,iY=0; //context.clearRect(aVertexX,aVertexY,digit[aNum][0].length*2*(aRadius+iGap),digit[aNum].length*2*(aRadius+iGap)) for(i=0;i<digit[aNum].length;i++){ for(j=0;j<digit[aNum][i].length;j++){ if(digit[aNum][i][j]){ context.beginPath(); context.strokeStyle="#eee"; context.fillStyle="#eee"; iX=aVertexX+(2*j+1)*(aRadius+iGap); iY=aVertexY+(2*i+1)*(aRadius+iGap); context.arc(iX,iY,aRadius,0,2*Math.PI); context.fill(); context.stroke(); context.closePath(); } } } } function fDrawClock(aTimeStr){ context.clearRect(0,0,WINDOW_WIDTH,WINDOW_HEIGHT); context.beginPath(); //console.log(pat) context.fillStyle=pat//cBgColor; context.fillRect(0,0,WINDOW_WIDTH,WINDOW_HEIGHT); context.closePath(); var i=0,iCurrentVertexX=iVertexX,iCurrentVertexY=iVertexY,iIndex=0; for(i=0;i<aTimeStr.length;i++){ if (/[0-9]/.test(aTimeStr[i])){ iIndex=aTimeStr[i] //console.log("iIndex is "+aTimeStr[i]) }else if(/\s/.test(aTimeStr[i])){ iIndex=12; //console.log("iIndex is "+iIndex) }else if(aTimeStr[i]===":"){ iIndex=10; //console.log("iIndex is "+aTimeStr[i]) }else if(aTimeStr[i]==="."){ iIndex=11; //console.log("iIndex is "+iIndex) } fNumDraw(iIndex,iRadius,iGap,iCurrentVertexX,iCurrentVertexY); //console.log("aTimeStr[i]:"+aTimeStr[i]+"sTimePrev[i]:"+sTimePrev[i]) if(aTimeStr[i]!=sTimePrev[i]){ fAddBalls(iIndex,iRadius,iCurrentVertexX,iCurrentVertexY); //console.log(aBalls); } iCurrentVertexX=iCurrentVertexX+(iRadius+iGap)*2*digit[iIndex][0].length; } fDrowBalls(); sTimePrev=aTimeStr; } function fShowClock(){ var sTimeStr=fGetTimeString(iShowLen); //@@ fDrawClock(sTimeStr); fBallsUpdate(); tShowClock=setTimeout(fShowClock,50); }; function fAddBalls(aNum,aRadius,aVertexX,aVertexY){ var oNewBall={},l1=digit[aNum].length; console.log(aBalls.length) for(i=0;i<l1;i++){ l2=digit[aNum][i].length for(j=0;j<l2;j++){ if(digit[aNum][i][j]){ oNewBall={} oNewBall.color=aColors[Math.floor(Math.random()*10)]; // x:400,y:200,g:2,vx:-4,vy:-3,r:7,color:"#005588" oNewBall.x=aVertexX+(2*j+1)*(aRadius+iGap); oNewBall.y=aVertexY+(2*i+1)*(aRadius+iGap); oNewBall.g=2; oNewBall.vx=(20*Math.random()-10)*0.5*((aBalls.length+200)/300); oNewBall.vy=-18*Math.random(); oNewBall.r=aRadius; aBalls.push(oNewBall); } } } //console.log(aBalls.length); }; function fDrowBalls(){ // console.log("aBalls.length:"+aBalls.length) l=aBalls.length; for(i=0;i<l;i++){ context.beginPath(); context.strokeStyle=aBalls[i].color; context.fillStyle=aBalls[i].color; //console.log(i,aBalls[i],aBalls[i].x,aBalls[i].y,aBalls[i].r) context.arc(aBalls[i].x,aBalls[i].y,aBalls[i].r,0,2*Math.PI) context.fill(); context.stroke(); //console.log("drawing") context.closePath(); // console.log(i) } //fNumDraw(); } function fBallsUpdate(){ var l=aBalls.length; var iUpdateBallsNum=-1; for(i=0;i<l;i++){ aBalls[i].x+=aBalls[i].vx; aBalls[i].vy+=aBalls[i].g; aBalls[i].y+=aBalls[i].vy; if(aBalls[i].y>=(WINDOW_HEIGHT-aBalls[i].r)){ aBalls[i].y=WINDOW_HEIGHT-aBalls[i].r; aBalls[i].vy=-aBalls[i].vy*0.75; } if(aBalls[i].x<=WINDOW_WIDTH+iRadius&&aBalls[i].x>=-iRadius){ iUpdateBallsNum++; aBalls[iUpdateBallsNum]=aBalls[i]; } } while(aBalls.length>iUpdateBallsNum+1){ aBalls.pop(); } } fShowClock(); //fNumDraw(iNum,8,1,200,200) //console.log(fGetTimeString(8)) } digit = [ [ [0,0,1,1,1,0,0], [0,1,1,0,1,1,0], [1,1,0,0,0,1,1], [1,1,0,0,0,1,1], [1,1,0,0,0,1,1], [1,1,0,0,0,1,1], [1,1,0,0,0,1,1], [1,1,0,0,0,1,1], [0,1,1,0,1,1,0], [0,0,1,1,1,0,0] ],//0 [ [0,0,0,1,1,0,0], [0,1,1,1,1,0,0], [0,0,0,1,1,0,0], [0,0,0,1,1,0,0], [0,0,0,1,1,0,0], [0,0,0,1,1,0,0], [0,0,0,1,1,0,0], [0,0,0,1,1,0,0], [0,0,0,1,1,0,0], [1,1,1,1,1,1,1] ],//1 [ [0,1,1,1,1,1,0], [1,1,0,0,0,1,1], [0,0,0,0,0,1,1], [0,0,0,0,1,1,0], [0,0,0,1,1,0,0], [0,0,1,1,0,0,0], [0,1,1,0,0,0,0], [1,1,0,0,0,0,0], [1,1,0,0,0,1,1], [1,1,1,1,1,1,1] ],//2 [ [1,1,1,1,1,1,1], [0,0,0,0,0,1,1], [0,0,0,0,1,1,0], [0,0,0,1,1,0,0], [0,0,1,1,1,0,0], [0,0,0,0,1,1,0], [0,0,0,0,0,1,1], [0,0,0,0,0,1,1], [1,1,0,0,0,1,1], [0,1,1,1,1,1,0] ],//3 [ [0,0,0,0,1,1,0], [0,0,0,1,1,1,0], [0,0,1,1,1,1,0], [0,1,1,0,1,1,0], [1,1,0,0,1,1,0], [1,1,1,1,1,1,1], [0,0,0,0,1,1,0], [0,0,0,0,1,1,0], [0,0,0,0,1,1,0], [0,0,0,1,1,1,1] ],//4 [ [1,1,1,1,1,1,1], [1,1,0,0,0,0,0], [1,1,0,0,0,0,0], [1,1,1,1,1,1,0], [0,0,0,0,0,1,1], [0,0,0,0,0,1,1], [0,0,0,0,0,1,1], [0,0,0,0,0,1,1], [1,1,0,0,0,1,1], [0,1,1,1,1,1,0] ],//5 [ [0,0,0,0,1,1,0], [0,0,1,1,0,0,0], [0,1,1,0,0,0,0], [1,1,0,0,0,0,0], [1,1,0,1,1,1,0], [1,1,0,0,0,1,1], [1,1,0,0,0,1,1], [1,1,0,0,0,1,1], [1,1,0,0,0,1,1], [0,1,1,1,1,1,0] ],//6 [ [1,1,1,1,1,1,1], [1,1,0,0,0,1,1], [0,0,0,0,1,1,0], [0,0,0,0,1,1,0], [0,0,0,1,1,0,0], [0,0,0,1,1,0,0], [0,0,1,1,0,0,0], [0,0,1,1,0,0,0], [0,0,1,1,0,0,0], [0,0,1,1,0,0,0] ],//7 [ [0,1,1,1,1,1,0], [1,1,0,0,0,1,1], [1,1,0,0,0,1,1], [1,1,0,0,0,1,1], [0,1,1,1,1,1,0], [1,1,0,0,0,1,1], [1,1,0,0,0,1,1], [1,1,0,0,0,1,1], [1,1,0,0,0,1,1], [0,1,1,1,1,1,0] ],//8 [ [0,1,1,1,1,1,0], [1,1,0,0,0,1,1], [1,1,0,0,0,1,1], [1,1,0,0,0,1,1], [0,1,1,1,0,1,1], [0,0,0,0,0,1,1], [0,0,0,0,0,1,1], [0,0,0,0,1,1,0], [0,0,0,1,1,0,0], [0,1,1,0,0,0,0] ],//9 [ [0,0,0,0], [0,0,0,0], [0,1,1,0], [0,1,1,0], [0,0,0,0], [0,0,0,0], [0,1,1,0], [0,1,1,0], [0,0,0,0], [0,0,0,0] ],//: [ [0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0], [0,1,1,0], [0,1,1,0] ],//"." [ [0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0] ]//" " ]; </script> </body> </html>
本站所有特效都是站长亲自测试后发布的,如果运行代码无效果,请复制到您的本机运行
运行代码
复制代码
另存代码
[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
转载请注明(B5教程网)原文链接::
https://b5.mxunkeji.com/content-151-244-1.html
相关热词搜索:
上一篇:
canvas-海底气泡圈圈
下一篇:
Canvas动画百分比加载
最新推荐
[
网络推广
]
24h无人值守共享自助洗车解
[
网络推广
]
微信小程商家wifi码是什么?
[
网络推广
]
企业光伏数据对接碳达峰系统
[
互联网资讯
]
CentOS官方已计划停止维护Ce
[
PHP教程
]
PHP 主力开发因生活压力不
[
网络营销
]
抖音自动关注、自动点赞、自
[
网络推广
]
阿里云优惠券|阿里云代金券|
[
网络推广
]
阿里云 ECS实例升级、续费
[
互联网资讯
]
我名下有几张移动电话卡?有
[
互联网资讯
]
互联网平台相互屏蔽网址链接
本周排行
[
HTML5+CSS3
]
bezierCurveTo绘制贝塞尔曲线
[
HTML5+CSS3
]
非常漂亮的Canvas弹性挂件
[
HTML5+CSS3
]
html5 canvas不断向上移动的色彩缤纷圆圈
[
HTML5+CSS3
]
css3炫酷效果发光字
[
HTML5+CSS3
]
css3实现圆圈来回移动效果
[
HTML5+CSS3
]
css实现3d图片翻转效果
[
HTML5+CSS3
]
html5 canvas实现开灯关灯
[
HTML5+CSS3
]
HTML5中用canvas绘制圆形
[
HTML5+CSS3
]
html5 canvas绘制类似方形螺线的图案
[
HTML5+CSS3
]
html5+canvas随机绘制圆形及坐标点击检测
关于我们
关于我们
赞助我们
加入我们
版权声明
联系我们
联系我们
QQ技术群
合作方式
广告服务
业务合作
常见问题
意见反馈
网站地图
在线投稿
积分获取
在线充值
本站不承担任何版权问题,如果我们侵犯了您的利益,请来信
告知(634381967@qq.com),我们会在第一时间处理!
© 苏ICP备20040182号
B5教程网 版权所有