JS文字球狀放大效果代碼分享
很酷的放大鏡放大文字的效果,超贊!
先展示一下效果圖:

大家先運(yùn)行代碼試一試-------------------------------------效果演示-------------------------------------------
具體代碼如下
<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?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 = 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>
小伙伴們想不想實(shí)現(xiàn)這種酷炫的效果,直接復(fù)制代碼,運(yùn)行即可,抓緊試試吧,或者是再來點(diǎn)創(chuàng)新。
以上就是為大家分享的JavaScript文字球狀放大效果代碼,希望大家可以喜歡。
相關(guān)文章
TypeScript條件類型與內(nèi)置條件類型超詳細(xì)講解
我們可以使用TypeScript中的條件類型來根據(jù)邏輯定義某些類型,就像是在編寫代碼那樣。它采用的語法和我們在JavaScript中熟悉的三元運(yùn)算符很像:condition ? ifConditionTrue : ifConditionFalse。我們來看看他是怎么工作的2023-03-03
Jjcarousellite 實(shí)現(xiàn)圖片列表滾動(dòng)的簡單實(shí)例
這篇文章主要介紹了Jjcarousellite 實(shí)現(xiàn)圖片列表滾動(dòng)的簡單實(shí)例,有需要的朋友可以參考一下2013-11-11
微信小程序開發(fā)實(shí)現(xiàn)首頁彈框活動(dòng)引導(dǎo)功能
自己x實(shí)現(xiàn)的一個(gè)比較簡單微信彈窗功能,主要就是教會大家對微信彈窗的用法和理解,這篇文章主要給大家介紹了關(guān)于微信小程序如何實(shí)現(xiàn)首頁彈框活動(dòng)引導(dǎo)功能的相關(guān)資料,需要的朋友可以參考下2021-08-08
js利用數(shù)組length屬性清空和截短數(shù)組的小例子
這篇文章主要介紹了js利用數(shù)組length屬性清空和截短數(shù)組的小例子,有需要的朋友可以參考一下2014-01-01
兩個(gè)JavaScript中的特殊值null和undefined詳解
Null和Undefined是JavaScript中非?;A(chǔ)和重要的概念,理解它們的含義、特點(diǎn)和使用方式對于避免出現(xiàn)錯(cuò)誤和編寫健壯的應(yīng)用程序非常重要,這篇文章主要介紹了兩個(gè)JavaScript中的特殊值null和undefined詳解,需要的朋友可以參考下2023-06-06
JS設(shè)置網(wǎng)頁圖片vspace和hspace屬性的方法
這篇文章主要介紹了JS設(shè)置網(wǎng)頁圖片vspace和hspace屬性的方法,具體分析了vspace和hspace屬性的功能及javascript修改技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-04-04

