JavaScript经典代码段

逐隐逐现的文字特效[推荐使用][适用于IE4++]
(修改显示的文字后根据说明进行共2步)

====1、以下代码放在一个新建页面的HTML的<body></body>区即可:[页面上必须什么都没有]

<html>
<head>
<TITLE>特效</TITLE> 
</head>
<script language=javaScript>
<!-- //
var thissize=20
var textfont="隶书"
var textcolor= new Array()
textcolor[0]="000000"
textcolor[1]="000000"
textcolor[2]="000000"
textcolor[3]="111111"
textcolor[4]="222222"
textcolor[5]="333333"
textcolor[6]="444444"
textcolor[7]="555555"
textcolor[8]="666666"
textcolor[9]="777777"
textcolor[10]="888888"
textcolor[11]="999999"
textcolor[12]="aaaaaa"
textcolor[13]="bbbbbb"
textcolor[14]="cccccc"
textcolor[15]="dddddd"
textcolor[16]="eeeeee"
textcolor[17]="ffffff"
textcolor[18]="ffffff"
var message = new Array()
message[0]="  
http://www.happydrips.com"  ;
message[1]="HappyDrips工作室"
message[2]="谢谢您使用"
message[3]="javascript源码大全"
i_message=0
var i_strength=0
var i_message=0
var timer
function glowtext() { 
if(document.all) {
if (i_strength <=17) {
glowdiv.innerText=message[i_message]
document.all.glowdiv.style.filter="glow(color="+textcolor[i_strength]+", strength=4)"
i_strength++
timer=setTimeout("glowtext()",100)
}
else {
clearTimeout(timer)
setTimeout("deglowtext()",1500)
}
}
}function deglowtext() { 
if(document.all) {
if (i_strength >=0) {
glowdiv.innerText=message[i_message]
document.all.glowdiv.style.filter="glow(color="+textcolor[i_strength]+", strength=4)"
i_strength--
timer=setTimeout("deglowtext()",100)
}
else {
clearTimeout(timer)
i_message++
if (i_message>=message.length) {i_message=0}
i_strength=0
intermezzo()
}
}
}
function intermezzo() { 
glowdiv.innerText=""
setTimeout("glowtext()",1500) 
}
//-->
</script>
<body bgcolor="#000000" onLoad="glowtext()"> //不要忘记写 
<div id="glowdiv" style="position:absolute;visibility:visible;width:600px;text-align:center; 
top:150px;left:50px;font-family:隶书;font-size:30pt;color:000000"></div>
</body>
</html>

====2、[可选项]修改<div>标签内的代码可以确定文字显示的位置,颜色和大小。
top是距离屏幕上面的距离,left是距离坐侧的距离。font-size是文字大小,
color是颜色。width是DIV层的宽度。由于文字是用DIV来控制的,所以在DIV的宽度范围内不能有其它内容。DIV的位置用绝对位置(position:absolute)表示。 








状态栏中的文字[修改显示的文字后复制到<body></body>]

<script language=JavaScript>
var MESSAGE="javascript源码大全"
var POSITION=100
var DELAY=5
var scroll=new statusMessageObject()
function statusMessageObject(p,d){
this.msg =MESSAGE
this.out =" "
this.pos =POSITION
this.delay=DELAY
this.i=0
this.reset=clearMessage}
function clearMessage(){
this.pos=POSITION}
function scroller(){
for (scroll.i=0;scroll.i<scroll.pos;scroll.i++){
scroll.out += " "}
if (scroll.pos >= 0)
scroll.out += scroll.msg
else scroll.out=scroll.msg.substring(-scroll.pos,scroll.msg.length)
window.status=scroll.out
scroll.out=" "
scroll.pos--
if (scroll.pos < -(scroll.msg.length)) {
scroll.reset()}
setTimeout('scroller()',scroll.delay)}
function snapIn(jumpSpaces,position){
var msg = scroll.msg
var out = ""
for(var i=0; i<position; i++) 
{out+= msg.charAt(i)}
for(i=1;i<jumpSpaces;i++) 
{out += " "}
out+=msg.charAt(position)
window.status = out
if(jumpSpaces <= 1) {
position++
if(msg.charAt(position) == ' ') 
{position++ }
jumpSpaces = 100-position
}else if (jumpSpaces > 3)
{jumpSpaces *= .75}
else
{jumpSpaces--}
if(position != msg.length) {
var cmd = "snapIn(" + jumpSpaces + "," + position + ")";
scrollID = window.setTimeout(cmd,scroll.delay);
}else{window.status=""
jumpSpaces=0
position=0
cmd = "snapIn(" + jumpSpaces + "," + position + ")";
scrollID = window.setTimeout(cmd,scroll.delay);
return false }
return true}
snapIn(100,0);
</script> 








不停闪烁的图片[修改显示的图片及链接地址后根据说明进行共1步]

====1、以下代码放在一个新建页面的HTML的<body></body> 区即可:[页面上必须什么都没有]

<HTML>
<HEAD>
<TITLE>Blink image</TITLE>
</HEAD>
<BODY ONLOAD="soccerOnload()" topmargin="0">
<DIV ID="soccer" STYLE="position:absolute; left:150; top:0">
<a href="http://图片的链接.com" target="_blank">
<IMG SRC="要显示的图片.gif" border="0"></a>
</DIV>
<SCRIPT LANGUAGE="JavaScript">
var msecs = 500; //改变时间得到不同的闪烁间隔;
var counter = 0; 
function soccerOnload() {
setTimeout("blink()", msecs);
}
function blink() {
soccer.style.visibility =
(soccer.style.visibility == "hidden") ? "visible" : "hidden";
counter +=1;
setTimeout("blink()", msecs);
}
</SCRIPT>
</BODY>
</HTML> 
 








跟随鼠标的萤火虫[无须修改][]共1步]

====1、将以下代码加入HEML的<body></body>之间:

<script language="JavaScript">
if (!document.layers&&!document.all)
event="test"
function showtip2(current,e,text){
if (document.all&&document.readyState=="complete"){
document.all.tooltip2.innerHTML='<marquee style="border:1px solid black">'+text+'</marquee>'
document.all.tooltip2.style.pixelLeft=event.clientX+document.body.scrollLeft+10
document.all.tooltip2.style.pixelTop=event.clientY+document.body.scrollTop+10
document.all.tooltip2.style.visibility="visible"}
else if (document.layers){
document.tooltip2.document.nstip.document.write('<b>'+text+'</b>')
document.tooltip2.document.nstip.document.close()
document.tooltip2.document.nstip.left=0
currentscroll=setInterval("scrolltip()",100)
document.tooltip2.left=e.pageX+10
document.tooltip2.top=e.pageY+10
document.tooltip2.visibility="show"}}
function hidetip2(){
if (document.all)
document.all.tooltip2.style.visibility="hidden"
else if (document.layers){
clearInterval(currentscroll)
document.tooltip2.visibility="hidden"}}
function scrolltip(){
if (document.tooltip2.document.nstip.left>=-document.tooltip2.document.nstip.document.width)
document.tooltip2.document.nstip.left-=5
else
document.tooltip2.document.nstip.left=150}
</script>
<script language="JavaScript">
function YY_Layerfx(yyleft,yytop,yyfnx,yyfny,yydiv,yybilder,yyloop,yyto,yycnt,yystep) { //v1.2
if ((document.layers)||(document.all)){
with (Math) {yynextx= eval(yyfnx)}
with (Math) {yynexty= eval(yyfny)}
yycnt=(yyloop && yycnt>=yystep*yybilder)?0:yycnt+yystep;
if (document.layers){
eval(yydiv+".top="+(yynexty+yytop))
eval(yydiv+".left="+(yynextx+yyleft)) }
if (document.all){
eval("yydiv=yydiv.replace(/.layers/gi, '.all')");
eval(yydiv+".style.pixelTop="+(yynexty+yytop));
eval(yydiv+".style.pixelLeft="+(yynextx+yyleft)); }
argStr='YY_Layerfx('+yyleft+','+yytop+',"'+yyfnx+'","'+yyfny+'","'+yydiv+'",'+yybilder+','+yyloop+','+yyto+','+yycnt+','+yystep+')';
if (yycnt<=yystep*yybilder){eval(yydiv+".yyto=setTimeout(argStr,yyto)");} }}
function YY_Mousetrace(evnt) { 
if (yyns4)
{if (evnt.pageX) {yy_ml=evnt.pageX; yy_mt=evnt.pageY;} }
else{
yy_ml=(event.clientX + document.body.scrollLeft);
yy_mt=(event.clientY + document.body.scrollTop);}
if (yy_tracescript)eval(yy_tracescript)}
</script>
<script language="JavaScript">
function PopWin()
{
var PopWin = window.open("new.htm","PopWin","toolbar=no,directries=no,scrollBars=yes,height=350,width=400");
}
</script>
<body>
<div id="tooltip2" style="position:absolute;visibility:hidden;clip:rect(0 150 50 0);width:150px;background-color:lightyellow">
<layer name="nstip" width="1000px" bgColor="lightyellow">
</layer>
</div>
<div id="yyd0"
style="position:absolute; left:10px; top:50px; width:3px; height:3px; z-index:1; background-color: #19636c; layer-background-color: #19636c; border: 1px none #000000; clip: rect(0 3 3 0)"></div><div
id="yyd1"
style="position:absolute; left:20px; top:50px; width:3px; height:3px; z-index:1; background-color: #708574; layer-background-color: #708574; border: 1px none #000000; clip: rect(0 3 3 0)"></div><div
id="yyd2"
style="position:absolute; left:30px; top:50px; width:3px; height:3px; z-index:1; background-color: #379bbf; layer-background-color: #379bbf; border: 1px none #000000; clip: rect(0 3 3 0)"></div><div
id="yyd3"
style="position:absolute; left:40px; top:50px; width:3px; height:3px; z-index:1; background-color: #25184c; layer-background-color: #25184c; border: 1px none #000000; clip: rect(0 3 3 0)"></div><div
id="yyd4"
style="position:absolute; left:50px; top:50px; width:3px; height:3px; z-index:1; background-color: #31bd3c; layer-background-color: #31bd3c; border: 1px none #000000; clip: rect(0 3 3 0)"></div><div
id="yyd5"
style="position:absolute; left:60px; top:50px; width:3px; height:3px; z-index:1; background-color: #c11efd; layer-background-color: #c11efd; border: 1px none #000000; clip: rect(0 3 3 0)"></div><script>
var yyns4=window.Event?true:false; var yy_mt = 0; var yy_ml = 0;
document.onmousemove = YY_Mousetrace;
yy_tracescript = '';
if (yyns4){ document.captureEvents(Event.mousemove);
YY_Mousetrace('',',document.YY_Mousetrace1')}
YY_Layerfx(0,0,'yy_ml+cos((15*sin(yycnt/39.83007847812662))+0)*150*(sin(10+yycnt/20)+0.2)*cos(yycnt/20)','yy_mt+sin((15*sin(yycnt/34.224861639800686))+0)*150*(sin(10+yycnt/20)+0.2)*cos(yycnt/20)','document.layers[/'yyd0/']',2000,true,80,0,1);
YY_Layerfx(0,0,'yy_ml+cos((15*sin(yycnt/27.66510707209673))+30)*150*(sin(10+yycnt/20)+0.2)*cos(yycnt/20)','yy_mt+sin((15*sin(yycnt/9.240632767417667))+30)*150*(sin(10+yycnt/20)+0.2)*cos(yycnt/20)','document.layers[/'yyd1/']',2000,true,80,0,1);
YY_Layerfx(0,0,'yy_ml+cos((15*sin(yycnt/16.45318944579641))+60)*150*(sin(10+yycnt/20)+0.2)*cos(yycnt/20)','yy_mt+sin((15*sin(yycnt/16.0564452288292))+60)*150*(sin(10+yycnt/20)+0.2)*cos(yycnt/20)','document.layers[/'yyd2/']',2000,true,80,0,1);
YY_Layerfx(0,0,'yy_ml+cos((15*sin(yycnt/6.95348954836835))+90)*150*(sin(10+yycnt/20)+0.2)*cos(yycnt/20)','yy_mt+sin((15*sin(yycnt/44.13697049887155))+90)*150*(sin(10+yycnt/20)+0.2)*cos(yycnt/20)','document.layers[/'yyd3/']',2000,true,80,0,1);
YY_Layerfx(0,0,'yy_ml+cos((15*sin(yycnt/33.90077294583733))+120)*150*(sin(10+yycnt/20)+0.2)*cos(yycnt/20)','yy_mt+sin((15*sin(yycnt/2.2378828869411587))+120)*150*(sin(10+yycnt/20)+0.2)*cos(yycnt/20)','document.layers[/'yyd4/']',2000,true,80,0,1);
YY_Layerfx(0,0,'yy_ml+cos((15*sin(yycnt/37.858312521039835))+150)*150*(sin(10+yycnt/20)+0.2)*cos(yycnt/20)','yy_mt+sin((15*sin(yycnt/18.083839795990098))+150)*150*(sin(10+yycnt/20)+0.2)*cos(yycnt/20)','document.layers[/'yyd5/']',2000,true,80,0,1);
</script>
</body> 









背景颜色自己选[推荐][共1步]

====1、以下是这个效果的全部代码。[最好从一个空页面开始]

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb_2312-80">
<title>新页面 </title>
</head>
<body>
<script language="JavaScript">
<!--
done = 0;
step = 4
function anim(yp,yk)
{
if(document.layers) document.layers["napis"].top=yp;
else document.all["napis"].style.top=yp;
if(yp>yk) step = -4
if(yp<60) step = 4
setTimeout('anim('+(yp+step)+','+yk+')', 35);
}
function start()
{
if(done) return
done = 1;
if(navigator.appName=="Netscape") {
document.napis.left=innerWidth/2 - 145;
anim(60,innerHeight - 60)
}
else {
napis.style.left=11;
anim(60,document.body.offsetHeight - 60)
}
}
//-->
</script>
<div id="napis"
style="position: absolute;top: -50;
color: #000000;font-family:宋体;font-size:9pt;">
</div><script language="JavaScript">
<!--
setTimeout('start()',10);
//-->
</script>
<script language="JavaScript">
<!-- Begin
function initArray() {
for (var i = 0; i < initArray.arguments.length; i++) {
this[i] = initArray.arguments[i];
}
this.length = initArray.arguments.length;
}
var colors = new initArray(
"#000000","#0000FF","#80FFFF","#80FF80","#FFFF00","#FF8000","#FF00FF","#FF0000"
);
delay = 100
link = 0;
vlink = 0;
function linkDance() {
link = (link+1)%colors.length;
vlink = (vlink+1)%colors.length;
document.linkColor = colors[link];
document.vlinkColor = colors[vlink];
setTimeout("linkDance()",delay);
}
linkDance();
// End -->
</script>
<script>
function colors(c1){
this.c1 = c1;
}
a00 = new colors("FFFBD0");
a01 = new colors("FF0000");
a02 = new colors("FF8080");
a03 = new colors("FF8000");
a04 = new colors("FFFF00");
a05 = new colors("000080");
a06 = new colors("0000FF");
a07 = new colors("008000");
a08 = new colors("00FF00");
a09 = new colors("804000");
a10 = new colors("808000");
a11 = new colors("000000");
a12 = new colors("FFFFFF");
a13 = new colors("C0C0C0");
a14 = new colors("408080");
a15 = new colors("808080");
a16 = new colors("D2BF51");
a17 = new colors("44BBE8");
a18 = new colors("C97AB9");
a19 = new colors("A2C97A");
a20 = new colors("804000");
a21 = new colors("6AE6C4");
a22 = new colors("33A3D1");
a23 = new colors("6C9AEE");
function changebg(type){
scheme = type;
document.bgColor = scheme.c1;
timerID=setTimeout('document.bgColor = scheme.c2', document.selector.value * 10);
}
</script>
<form NAME="selector">
<p><input TYPE="button" onClick="changebg(a00)" style="background-color: rgb(255,251,208)"><input
TYPE="button" onClick="changebg(a01)" style="background-color: rgb(255,0,0)"><input
TYPE="button" onClick="changebg(a02)" style="background-color: rgb(255,128,128)"><input
TYPE="button" onClick="changebg(a03)" style="background-color: rgb(255,128,0)"><input
TYPE="button" onClick="changebg(a04)" style="background-color: rgb(255,255,0)"><input
TYPE="button" onClick="changebg(a05)" style="background-color: rgb(0,0,128)"><input
TYPE="button" onClick="changebg(a06)" style="background-color: rgb(0,0,255)"><input
TYPE="button" onClick="changebg(a07)" style="background-color: rgb(0,128,0)"><input
TYPE="button" onClick="changebg(a08)" style="background-color: rgb(0,255,0)"><input
TYPE="button" onClick="changebg(a09)" style="background-color: rgb(128,0,0)"><input
TYPE="button" onClick="changebg(a10)" style="background-color: rgb(128,128,0)"><input
TYPE="button" onClick="changebg(a11)" style="background-color: rgb(0,0,0)"><input
TYPE="button" onClick="changebg(a12)" style="background-color: rgb(255,255,255)"><input
TYPE="button" onClick="changebg(a13)" style="background-color: rgb(192,192,192)"><input
TYPE="button" onClick="changebg(a14)" style="background-color: rgb(64,128,128)"><input
TYPE="button" onClick="changebg(a15)" style="background-color: rgb(128,128,128)"><input
TYPE="button" onClick="changebg(a16)" style="background-color: rgb(210,191,81)"><input
TYPE="button" onClick="changebg(a17)" style="background-color: rgb(68,187,232)"><input
TYPE="button" onClick="changebg(a18)" style="background-color: rgb(201,122,185)"><input
TYPE="button" onClick="changebg(a19)" style="background-color: rgb(162,201,122)"><input
TYPE="button" onClick="changebg(a20)" style="background-color: rgb(106,230,196)"><input
TYPE="button" onClick="changebg(a21)" style="background-color: rgb(194,219,185)"><input
TYPE="button" onClick="changebg(a22)" style="background-color: rgb(51,163,209)"><input
TYPE="button" onClick="changebg(a23)" style="background-color: rgb(108,154,238)"> </p>
</form>
</body>
</html> 







分时问候[修改显示的文字][共1步]

====1、将以下代码加入HTML 的<body></body>之间:

<script language="javaScript">
<!--
now = new Date(),hour = now.getHours()
if(hour < 6){document.write("凌晨好!")}
else if (hour < 9){document.write("早上好!")}
else if (hour < 12){document.write("上午好!")}
else if (hour < 14){document.write("中午好!")}
else if (hour < 17){document.write("下午好!")}
else if (hour < 19){document.write("傍晚好!")}
else if (hour < 22){document.write("晚上好!")}
else {document.write("夜里好!")}
// -->
</script> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值