JS特效--跟隨滑鼠移動的日曆時鐘
跟隨滑鼠移動的日曆時鐘
介紹:想讓你的頁面有趣一點,又不想要麻煩,這個程式碼很適合你喔
使用方法:直接插入到<head></head>之間即可
<SCRIPT language=JavaScript>
<!--
dCol='yellow'; //定義日曆顏色
fCol='#ff0000'; //定義1-12這12個數的顏色
sCol='#00ff00'; //定義秒針顏色
mCol='#0000ff'; //定義分針顏色
hCol='#ff0000'; //定義時針顏色
ClockHeight=40; //定義時鐘的高度
ClockWidth=40; //定義時鐘的寬度
ClockFromMouseY=0; //定義時鐘的中心距滑鼠的相對垂直距離
ClockFromMouseX=100; //定義時鐘中心距滑鼠的相對水平距離
//以上顏色值你要據你頁面的背景顏色進行修改!注意不要你頁面的背景色一致哦。
d=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
m=new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月",
"十月","十一月","十二月"); //以上是給定星期和月份的取值範圍
date=new Date();
day=date.getDate(); //取得當前日期命令
year=date.getYear(); //取得當前年份命令
if (year < 2000) year=year+1900;
TodaysDate="年 "+m[date.getMonth()]+" "+day+"日 "+d[date.getDay()]+" "+year;
D=TodaysDate.split(''); //顯示“某年某月某日”
H='...';
H=H.split('');
M='....';
M=M.split('');
S='.....';
S=S.split(''); //使秒、分、時針反向相應的位置
Face='1 2 3 4 5 6 7 8 9 10 11 12';
font='Arial';
size=1; //定義秒、分、時針及1-12等字元的宋體、大小(最好匆改動哦)
speed=0.8; //定義一旦滑鼠位置發生變化時所有相關字元跟隨至前面指定的滑鼠的相對位置的速度,
能看到各字元的軌跡,值可在0.1-1.0之間改動(值最小為0.1時跟隨過來的速度最慢,值為1.0時跟隨速度最快且與軌跡顯示)
ns=(document.layers);
ie=(document.all); //說明在NS和IE兩種不同瀏覽器裡都適用
//以下的大段語句定義了NS和IE瀏覽器各自如何控制並完成時間和旋轉的日曆跟隨滑鼠轉的
Face=Face.split(' ');
n=Face.length;
a=size*10;
ymouse=0;
xmouse=0;
scrll=0;
props="<font face="+font+" size="+size+" color="+fCol+">";
props2="<font face="+font+" size="+size+" color="+dCol+">";
Split=360/n;
Dsplit=360/D.length;
HandHeight=ClockHeight/4.5
HandWidth=ClockWidth/4.5
HandY=-7;
HandX=-2.5;
scrll=0;
step=0.06;
currStep=0;
y=new Array();x=new Array();Y=new Array();X=new Array();
for (i=0; i < n; i++){y[i]=0;x[i]=0;Y[i]=0;X[i]=0}
Dy=new Array();Dx=new Array();DY=new Array();DX=new Array();
for (i=0; i < D.length; i++){Dy[i]=0;Dx[i]=0;DY[i]=0;DX[i]=0}
if (ns){
for (i=0; i < D.length; i++)
document.write('<layer name="nsDate'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props2+D[i]+'</font></center></layer>');
for (i=0; i < n; i++)
document.write('<layer name="nsFace'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props+Face[i]+'</font></center></layer>');
for (i=0; i < S.length; i++)
document.write('<layer name=nsSeconds'+i+' top=0 left=0 width=15
height=15><font face=Arial size=3 color='+sCol+'><center><b>'+S[i]+'</b></center></font></layer>');
for (i=0; i < M.length; i++)
document.write('<layer name=nsMinutes'+i+' top=0 left=0 width=15
height=15><font face=Arial size=3 color='+mCol+'><center><b>'+M[i]+'</b></center></font></layer>');
for (i=0; i < H.length; i++)
document.write('<layer name=nsHours'+i+' top=0 left=0 width=15
height=15><font face=Arial size=3 color='+hCol+'><center><b>'+H[i]+'</b></center></font></layer>');
}
if (ie){
document.write('<div id="Od" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < D.length; i++)
document.write('<div id="ieDate" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props2+D[i]+'</font></div>');
document.write('</div></div>');
document.write('<div id="Of" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < n; i++)
document.write('<div id="ieFace" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props+Face[i]+'</font></div>');
document.write('</div></div>');
document.write('<div id="Oh" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < H.length; i++)
document.write('<div id="ieHours" style="position:absolute;width:16px;
height:16px;font-family:Arial;font-size:16px;color:'+hCol+';text-align:center;font-weight:bold">'+H[i]+'</div>');
document.write('</div></div>');
document.write('<div id="Om" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < M.length; i++)
document.write('<div id="ieMinutes" style="position:absolute;width:16px;
height:16px;font-family:Arial;font-size:16px;color:'+mCol+';text-align:center;font-weight:bold">'+M[i]+'</div>');
document.write('</div></div>')
document.write('<div id="Os" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < S.length; i++)
document.write('<div id="ieSeconds" style="position:absolute;width:16px;
height:16px;font-family:Arial;font-size:16px;color:'+sCol+';text-align:center;font-weight:bold">'+S[i]+'</div>');
document.write('</div></div>')
}
(ns)?window.captureEvents(Event.MOUSEMOVE):0;
function Mouse(evnt){
ymouse = (ns)?evnt.pageY+ClockFromMouseY-(window.pageYOffset):
event.y+ClockFromMouseY;
xmouse = (ns)?evnt.pageX+ClockFromMouseX:event.x+ClockFromMouseX;
}
(ns)?window.onMouseMove=Mouse:document.onmousemove=Mouse;
function ClockAndAssign(){
time = new Date ();
secs = time.getSeconds();
sec = -1.57 + Math.PI * secs/30;
mins = time.getMinutes();
min = -1.57 + Math.PI * mins/30;
hr = time.getHours();
hrs = -1.575 + Math.PI * hr/6+Math.PI*parseInt(time.getMinutes())/360;
if (ie){
Od.style.top=window.document.body.scrollTop;
Of.style.top=window.document.body.scrollTop;
Oh.style.top=window.document.body.scrollTop;
Om.style.top=window.document.body.scrollTop;
Os.style.top=window.document.body.scrollTop;
}
for (i=0; i < n; i++){
var F=(ns)?document.layers['nsFace'+i]:ieFace[i].style;
F.top=y[i] + ClockHeight*Math.sin(-1.0471 + i*Split*Math.PI/180)+scrll;
F.left=x[i] + ClockWidth*Math.cos(-1.0471 + i*Split*Math.PI/180);
}
for (i=0; i < H.length; i++){
var HL=(ns)?document.layers['nsHours'+i]:ieHours[i].style;
HL.top=y[i]+HandY+(i*HandHeight)*Math.sin(hrs)+scrll;
HL.left=x[i]+HandX+(i*HandWidth)*Math.cos(hrs);
}
for (i=0; i < M.length; i++){
var ML=(ns)?document.layers['nsMinutes'+i]:ieMinutes[i].style;
ML.top=y[i]+HandY+(i*HandHeight)*Math.sin(min)+scrll;
ML.left=x[i]+HandX+(i*HandWidth)*Math.cos(min);
}
for (i=0; i < S.length; i++){
var SL=(ns)?document.layers['nsSeconds'+i]:ieSeconds[i].style;
SL.top=y[i]+HandY+(i*HandHeight)*Math.sin(sec)+scrll;
SL.left=x[i]+HandX+(i*HandWidth)*Math.cos(sec);
}
for (i=0; i < D.length; i++){
var DL=(ns)?document.layers['nsDate'+i]:ieDate[i].style;
DL.top=Dy[i] + ClockHeight*1.5*Math.sin(currStep+i*Dsplit*Math.PI/180)+scrll;
DL.left=Dx[i] + ClockWidth*1.5*Math.cos(currStep+i*Dsplit*Math.PI/180);
}
currStep-=step;
}
function Delay(){
scrll=(ns)?window.pageYOffset:0;
Dy[0]=Math.round(DY[0]+=((ymouse)-DY[0])*speed);
Dx[0]=Math.round(DX[0]+=((xmouse)-DX[0])*speed);
for (i=1; i < D.length; i++){
Dy[i]=Math.round(DY[i]+=(Dy[i-1]-DY[i])*speed);
Dx[i]=Math.round(DX[i]+=(Dx[i-1]-DX[i])*speed);
}
y[0]=Math.round(Y[0]+=((ymouse)-Y[0])*speed);
x[0]=Math.round(X[0]+=((xmouse)-X[0])*speed);
for (i=1; i < n; i++){
y[i]=Math.round(Y[i]+=(y[i-1]-Y[i])*speed);
x[i]=Math.round(X[i]+=(x[i-1]-X[i])*speed);
}
ClockAndAssign();
setTimeout('Delay()',20);
}
if (ns||ie)window.onload=Delay;
//-->
</SCRIPT>
來個縮排版本,看起來舒服一點
<SCRIPT language=JavaScript>
!--
dCol='yellow'; //定義日曆顏色
fCol='#ff0000'; //定義1-12這12個數的顏色
sCol='#00ff00'; //定義秒針顏色
mCol='#0000ff'; //定義分針顏色
hCol='#ff0000'; //定義時針顏色
ClockHeight=40; //定義時鐘的高度
ClockWidth=40; //定義時鐘的寬度
ClockFromMouseY=0; //定義時鐘的中心距滑鼠的相對垂直距離
ClockFromMouseX=100; //定義時鐘中心距滑鼠的相對水平距離
//以上顏色值你要據你頁面的背景顏色進行修改!注意不要你頁面的背景色一致
d=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
m=new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"); //以上是給定星期和月份的取值範圍
date=new Date();
day=date.getDate(); //取得當前日期命令
year=date.getYear(); //取得當前年份命令
if (year < 2000)
year=year+1900;
TodaysDate="年 "+m[date.getMonth()]+" "+day+"日 "+d[date.getDay()]+" "+year;
D=TodaysDate.split(''); //顯示“某年某月某日”
H='...';
H=H.split('');
M='....';
M=M.split('');
S='.....';
S=S.split(''); //使秒、分、時針反向相應的位置
Face='1 2 3 4 5 6 7 8 9 10 11 12';
font='Arial';
size=1; //定義秒、分、時針及1-12等字元的宋體、大小(最好匆改動哦)
speed=0.8; //定義一旦滑鼠位置發生變化時所有相關字元跟隨至前面指定的滑鼠的相對位置的速度,能看到各字元的軌跡,值可在0.1-1.0之間改動(值最小為0.1時跟隨過來的速度最慢,值為1.0時跟隨速度最快且與軌跡顯示)
ns=(document.layers);
ie=(document.all); //說明在NS和IE兩種不同瀏覽器裡都適用
//以下的大段語句定義了NS和IE瀏覽器各自如何控制並完成時間和旋轉的日曆跟隨滑鼠轉的
Face=Face.split(' ');
n=Face.length;
a=size*10;
ymouse=0;
xmouse=0;
scrll=0;
props="<font face="+font+" size="+size+" color="+fCol+">";
props2="<font face="+font+" size="+size+" color="+dCol+">";
Split=360/n;
Dsplit=360/D.length;
HandHeight=ClockHeight/4.5
HandWidth=ClockWidth/4.5
HandY=-7;
HandX=-2.5;
scrll=0;
step=0.06;
currStep=0;
y=new Array();
x=new Array();Y=new Array();X=new Array();
for (i=0; i < n; i++){
y[i]=0;x[i]=0;Y[i]=0;X[i]=0
}
Dy=new Array();
Dx=new Array();DY=new Array();
DX=new Array();
for (i=0; i < D.length; i++){
Dy[i]=0;Dx[i]=0;DY[i]=0;DX[i]=0
}
if (ns){
for (i=0; i < D.length; i++)
document.write('<layer name="nsDate'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props2+D[i]+'</font></center></layer>');
for (i=0; i < n; i++)
document.write('<layer name="nsFace'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props+Face[i]+'</font></center></layer>');
for (i=0; i < S.length; i++)
document.write('<layer name=nsSeconds'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+sCol+'><center><b>'+S[i]+'</b></center></font></layer>');
for (i=0; i < M.length; i++)
document.write('<layer name=nsMinutes'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+mCol+'><center><b>'+M[i]+'</b></center></font></layer>');
for (i=0; i < H.length; i++)
document.write('<layer name=nsHours'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+hCol+'><center><b>'+H[i]+'</b></center></font></layer>');
}
if (ie){
document.write('<div id="Od" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < D.length; i++)
document.write('<div id="ieDate" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props2+D[i]+'</font></div>');
document.write('</div></div>');
document.write('<div id="Of" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < n; i++)
document.write('<div id="ieFace" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props+Face[i]+'</font></div>');
document.write('</div></div>');
document.write('<div id="Oh" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < H.length; i++)
document.write('<div id="ieHours" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+hCol+';text-align:center;font-weight:bold">'+H[i]+'</div>');
document.write('</div></div>');
document.write('<div id="Om" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < M.length; i++)
document.write('<div id="ieMinutes" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+mCol+';text-align:center;font-weight:bold">'+M[i]+'</div>');
document.write('</div></div>')
document.write('<div id="Os" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < S.length; i++)
document.write('<div id="ieSeconds" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+sCol+';text-align:center;font-weight:bold">'+S[i]+'</div>');
document.write('</div></div>')
}
(ns)?window.captureEvents(Event.MOUSEMOVE):0;
function Mouse(evnt){
ymouse = (ns)?evnt.pageY+ClockFromMouseY-(window.pageYOffset):
event.y+ClockFromMouseY;
xmouse = (ns)?evnt.pageX+ClockFromMouseX:event.x+ClockFromMouseX;
}
(ns)?window.onMouseMove=Mouse:document.onmousemove=Mouse;
function ClockAndAssign(){
time = new Date ();
secs = time.getSeconds();
sec = -1.57 + Math.PI * secs/30;
mins = time.getMinutes();
min = -1.57 + Math.PI * mins/30;
hr = time.getHours();
hrs = -1.575 + Math.PI * hr/6+Math.PI*parseInt(time.getMinutes())/360;
if (ie){
Od.style.top=window.document.body.scrollTop;
Of.style.top=window.document.body.scrollTop;
Oh.style.top=window.document.body.scrollTop;
Om.style.top=window.document.body.scrollTop;
Os.style.top=window.document.body.scrollTop;
}
for (i=0; i < n; i++){
var F=(ns)?document.layers['nsFace'+i]:ieFace[i].style;
F.top=y[i] + ClockHeight*Math.sin(-1.0471 + i*Split*Math.PI/180)+scrll;
F.left=x[i] + ClockWidth*Math.cos(-1.0471 + i*Split*Math.PI/180);
}
for (i=0; i < H.length; i++){
var HL=(ns)?document.layers['nsHours'+i]:ieHours[i].style;
HL.top=y[i]+HandY+(i*HandHeight)*Math.sin(hrs)+scrll;
HL.left=x[i]+HandX+(i*HandWidth)*Math.cos(hrs);
}
for (i=0; i < M.length; i++){
var ML=(ns)?document.layers['nsMinutes'+i]:ieMinutes[i].style;
ML.top=y[i]+HandY+(i*HandHeight)*Math.sin(min)+scrll;
ML.left=x[i]+HandX+(i*HandWidth)*Math.cos(min);
}
for (i=0; i < S.length; i++){
var SL=(ns)?document.layers['nsSeconds'+i]:ieSeconds[i].style;
SL.top=y[i]+HandY+(i*HandHeight)*Math.sin(sec)+scrll;
SL.left=x[i]+HandX+(i*HandWidth)*Math.cos(sec);
}
for (i=0; i < D.length; i++){
var DL=(ns)?document.layers['nsDate'+i]:ieDate[i].style;
DL.top=Dy[i] + ClockHeight*1.5*Math.sin(currStep+i*Dsplit*Math.PI/180)+scrll;
DL.left=Dx[i] + ClockWidth*1.5*Math.cos(currStep+i*Dsplit*Math.PI/180);
}
currStep-=step;
}
function Delay(){
scrll=(ns)?window.pageYOffset:0;
Dy[0]=Math.round(DY[0]+=((ymouse)-DY[0])*speed);
Dx[0]=Math.round(DX[0]+=((xmouse)-DX[0])*speed);
for (i=1; i < D.length; i++){
Dy[i]=Math.round(DY[i]+=(Dy[i-1]-DY[i])*speed);
Dx[i]=Math.round(DX[i]+=(Dx[i-1]-DX[i])*speed);
}
y[0]=Math.round(Y[0]+=((ymouse)-Y[0])*speed);
x[0]=Math.round(X[0]+=((xmouse)-X[0])*speed);
for (i=1; i < n; i++){
y[i]=Math.round(Y[i]+=(y[i-1]-Y[i])*speed);
x[i]=Math.round(X[i]+=(x[i-1]-X[i])*speed);
}
ClockAndAssign();
setTimeout('Delay()',20);
}
if (ns||ie)
window.onload=Delay;
//-->
</SCRIPT>
相關文章
- js跟隨滑鼠移動的元素JS
- JavaScript跟隨滑鼠移動的圖片效果JavaScript
- 跟隨滑鼠走的時鐘[跨瀏覽器支援]瀏覽器
- 【canvas】箭頭跟隨滑鼠移動的動畫原理Canvas動畫
- jQuery跟隨滑鼠移動的彈出層效果jQuery
- JavaScript:一個滑鼠動態跟隨文字特效的示例 (轉)JavaScript特效
- JavaScript 元素跟隨滑鼠運動JavaScript
- [unity3d]如何實現遊戲物件跟隨滑鼠方向移動Unity3D遊戲物件
- js實現彈出層滑鼠跟隨效果JS
- 帶時分秒的JS日曆控JS
- js年月日小時分鐘秒動態時鐘效果JS
- 移動端中踩過的關於日曆&時間的坑
- jquery css3跟隨滑鼠晃動的圖片效果jQueryCSSS3
- 移動端仿ios日曆外掛iOS
- Calendar -『為移動端而生』的自定義日曆
- 移動端div跟隨滾動條滾動(自制
- JavaScript 跟隨滑鼠指標的粒子效果JavaScript指標
- 蘋果Mac必備:Dato 日曆和時區的選單欄時鐘工具蘋果Mac
- 利用js製作簡單的動態日曆JS
- 小說APP原始碼,手動滑動輪播圖時,輪播圖跟隨移動APP原始碼
- JavaScript、CSS實現滑鼠跟隨繁花效果JavaScriptCSS
- js手寫日曆JS
- JS編寫日曆控制元件(支援單日曆 雙日曆 甚至多日曆等)JS控制元件
- 移動端日曆元件設計與實現元件
- 滑鼠懸浮彈出滑鼠跟隨層程式碼例項
- JS日曆控制元件優化(增加時分秒)JS控制元件優化
- 8個基於jQuery和HTML5的日曆時鐘外掛jQueryHTML
- canvas實現的跟隨滑鼠的彩色絲帶效果Canvas
- 讓互動更加生動!有意思的滑鼠跟隨 3D 旋轉動效3D
- JS動態相簿--隨滑鼠所至切換封面圖JS
- CSS mask 實現滑鼠跟隨鏤空效果CSS
- 滑鼠指標一長串元素跟隨效果指標
- 不可思議的純 CSS 實現滑鼠跟隨效果CSS
- 自定義圓形View:實現跟隨手指移動的小球View
- three.js 利用滑鼠移動攝像機JS
- 原生JS控制多個滾動條同步跟隨滾動JS
- jQuery手機移動端農曆公曆日期時間選擇程式碼jQuery
- 一側具有滑鼠跟隨效果的垂直導航選單