首頁 > web前端 > js教程 > 主體

JS文字球狀放大效果程式碼分享_javascript技巧

WBOY
發布: 2016-05-16 15:44:09
原創
1702 人瀏覽過

很酷的放大鏡放大文字的效果,超讚!

先展示一下效果圖:

大家先運行程式碼試試看-------------------------------------效果示範-------------------------------------------

具體程式碼如下

<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; top:0; width:100%; height:100%;}
 span {position:absolute;font-family: verdana; font-weight: bold;}
</style>

<script type="text/javascript"><!--

T = "What is real&#63;How do you define real&#63; 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 = i*2*W;
 this.y0 = j*2*H;
 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;
 top = 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;
 top = 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;
 top = -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%;top:50%">
 <span id="doot"></span>
</span>

</body>
</html>
登入後複製

小夥伴們想不想實現這種酷炫的效果,直接複製程式碼,運行即可,抓緊試試吧,或者是再來點創新。

以上就是為大家分享的JavaScript文字球狀放大效果程式碼,希望大家可以喜歡。

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板