JS文字球状放大效果代码分享
网络编程 2021-07-04 21:48www.168986.cn编程入门
这篇文章主要展示了JS文字球状放大效果,和放大镜放大文字一样,很神奇的代码,感兴趣的小伙伴们可以参考一下
很酷的放大镜放大文字的效果,超赞!
先展示一下效果图
大家先运行代码试一试--------------------------------------------------------------------------------
具体代码如下
<html> <head> <title>JS文字球状放大效果</title> <meta http-equiv="imagetoolbar" content="no"> <style type="text/css"> body {cursor:crosshair;margin:0; padding:0; position:absolute; overflow:hidden; background:#000; left:0; :0; width:100%; height:100%;} span {position:absolute;font-family: verdana; font-weight: bold;} </style> <script type="text/javascript"><!-- T = "What is real?How do you define real? Ifyou're talkingabout what youcan feel whatyou can smellwhat you cantaste and seethen real issimply electrical signalsinterpreted byyour brain! "; I = 0; o = new Array(); xm = -1000; ym = -1000; /////////////// rad = 80; dim = 200; /////////////// W = 0; H = 0; NX = 14; NY = 14; var nx; var ny; document.onmousemove = function(e){ if (window.event) e = window.event; xm = (e.x || e.clientX) - (nx .5) + dim .5; ym = (e.y || e.clientY) - (ny .5) + dim .5; } function resize() { nx = document.body.offsetWidth; ny = document.body.offsetHeight; } onresize = resize; function CObj(N,i,j,c){ this.obj = document.createElement("span"); this.obj.innerHTML = c; DOOT.appendChild(this.obj); this.N = N; this.To = 16; this.x0 = i2W; this.y0 = j2H; this.anim = true; this.mainloop = function(){ with (this) { dx = xm - x0; dy = ym - y0; dist = Math.sqrt(dx dx + dy dy); if (dist < rad) { anim = true; M = Math.cos(.5 Math.PI Math.abs(dist / rad)); c = Math.round(84 + M 171); with(obj.style){ left = x0 - dx M; = y0 - dy M; zIndex = Math.round(100 + M); fontSize = 8 + M W 2; color = "RGB("+c+","+c+","+c+")"; } } else { if(anim){ with(obj.style){ left = x0; = y0; zIndex = 0; fontSize = 8; color = "RGB(88,88,88)"; } anim = false; } } } } } function run(){ for(i in o)o[i].mainloop(); setTimeout(run,16); } onload = function (){ DOOT = document.getElementById("doot"); with(DOOT.style){ left = -dim/2; = -dim/2; width = dim; height = dim; } resize(); W = (dim / NX) / 2; H = (dim / NY) / 2; K = 0; for(var j=0;j<NY;j++){ for(var i=0;i<NX;i++){ c=T.charAt((I++)%T.length).toUpperCase(); if(c==" ")c="·"; o[K] = new CObj(K++,i,j,c); } } run(); } //--> </script> </head> <body> <span style="position:absolute;left:50%;:50%"> <span id="doot"></span> </span> </body> </html>
小伙伴们想不想实现这种酷炫的效果,直接复制代码,运行即可,抓紧试试吧,或者是再来点创新。
以上就是为大家分享的JavaScript文字球状放大效果代码,希望大家可以喜欢。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程