js特效代码(炫酷的js特效代码)

大家好,今天给各位分享js特效代码的一些知识,其中也会对炫酷的js特效代码进行解释,文章篇幅可能偏长,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在就马上开始吧!

在互联网的世界里,网页就像一本好书,而JavaScript特效代码则是那些让人眼前一亮的插画。今天,就让我带你走进JavaScript特效代码的世界,一起探索如何让你的网页动起来!

一、什么是JavaScript特效代码?

JavaScript特效代码,顾名思义,就是利用JavaScript语言编写的,用于实现网页动态效果的代码。这些效果可以是简单的文字闪烁、图片轮播,也可以是复杂的动画、交互等。

二、JavaScript特效代码的作用

1. 提升用户体验:通过特效代码,可以让网页更加生动、有趣,从而提升用户的浏览体验。

2. 增加网页吸引力:独特的特效可以吸引更多用户的注意力,提高网页的点击率。

3. 增强网站竞争力:在众多网页中,拥有特效的网站往往更具竞争力。

三、JavaScript特效代码的分类

1. 文字特效:如文字闪烁、文字阴影、文字渐变等。

2. 图片特效:如图片轮播、图片放大缩小、图片淡入淡出等。

3. 动画特效:如CSS3动画、jQuery动画等。

4. 交互特效:如鼠标跟随、键盘事件、表单验证等。

四、JavaScript特效代码的编写方法

下面,我将通过一个简单的例子,向大家介绍JavaScript特效代码的编写方法。

1. 准备工作

我们需要创建一个HTML文件,并在其中添加一个用于显示文字的`div`元素。

“`html

javascript

一种由Netscape的LiveScript发展而来的脚本语言,它提高与Java的兼容性。JavaScript采用HTML页作为其接口

一、Javascript在网页的用法

Javascript加入网页有两种方法:

1、直接加入HTML文档

这是最常用的方法,大部分含有Javascript的网页都采用这种方法,如:

<script language=”Javascript”>

<!–

document.writeln(“这是Javascript!采用直接插入的方法!”);

//-Javascript结束–>

</script>

在这个例子中,我们可看到一个新的标签:<script>……</script>,而<script language=”Javascript”>用来告诉浏览器这是用Javascript编写的程序,需要调动相应的解释程序进行解释。

HTML的注释标签<!–和–>:用来去掉浏览器所不能识别的Javascript源代码的,这对不支持 Javascript语言的浏览器来说是很有用的。

//-Javascript结束:双斜杠表示 Javascript的注释部分,即从//开始到行尾的字符都被忽略。至于程序中所用到的document.write()函数则表示将括号中的文字输出到窗口中去,这在后面将会详细介绍。另外一点需要注意的是,<script>……</script>的位置并不是固定的,可以包含在< head>……</head>或<body>…..</body>中的任何地方。

2、引用方式如果已经存在一个Javascript源文件(以js为扩展名),则可以采用这种引用的方式,以提高程序代码的利用率。其基本格式如下:

<script src=url language=”Javascript”></script>

其中的Url就是程序文件的地址。同样的,这样的语句可以放在HTML文档头部或主体的任何部分。如果要实现“直接插入方式”中所举例子的效果,可以首先创建一个Javascript源代码文件“Script.js”,其内容如下:

document.writeln(“这是Javascript!采用直接插入的方法!”);

在网页中可以这样调用程序:<script src=”Script.js” language=”Javascript”></script>。

谁能告诉我一些有用的网页特效代码啊

常用JS代码集锦层的隐藏与显示

只要设置style的display属性即可

比如<div style=”display:none” id=”MyDiv”>隐藏的层</div>

如果要显示它可以通过脚本来控制

window.document.getElementById(“MyDiv”).style.display=””;

禁止右键

<body oncontextmenu=”return false”>

屏蔽页面中程序运行出错信息

window.onerror= function()

{

return true;

}

得到当前显示器的分辨率

window.srceen.width得到屏幕的宽度

window.srceen.height得到屏幕的高度

如果当前分辨率为800*600,window.srceen.width是800,window.srceen.height是600

定时运行特定代码

setTimeout(Code,Timeout);

setInterval(Code,Timeout);

Code是一段字符串,里边是js代码,Timeout是时间间隔,单位是微秒

setTimeout是从现在算起多少微秒后运行该代码(只运行一次)

setInterval是每隔多少微秒运行一次代码

得到本页网址

var Url= window.location.href;

保存当前页面的内容

document.execCommand(“SaveAs”,””,”C:\\index.htm”);

隐去浏览器中当鼠标移到图片上跳出的工具栏

<img galleryimg=”no”>

或者

<head>

<meta http-equiv=”imagetoolbar” content=”no”>

</head>

■打开■

<input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打开>

<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>

■另存为■

<input name=Button onClick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存为><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>

■属性■

<input name=Button onClick=document.all.WebBrowser.ExecWB(10,1) type=button value=属性><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>

■打印■

<input name=Button onClick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>

■页面设置■

<input name=Button onClick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>

■刷新■

<input type=button value=刷新 name=refresh onclick=”window.location.reload()”>

■导入收藏■

<input type=”button” name=”Button” value=”导入收藏夹” onClick=window.external.ImportExportFavorites(true,);>

■导出收藏■

<input type=”button” name=”Button3″ value=”导出收藏夹” onClick=window.external.ImportExportFavorites(false,);>

■加入收藏■

<INPUT name=Button2 onclick=”window.external.AddFavorite(location.href, document.title)” type=button value=加入收藏夹>

■整理收藏夹■

<INPUT name=Submit2 onclick=”window.external.ShowBrowserUI(OrganizeFavorites, null)” type=button value=整理收藏夹>

■查看原文件■

<INPUT name=Button onclick=window.location=”view-source:”+ window.location.href type=button value=查看源文件>

■语言设置■

<INPUT name=Button onclick=”window.external.ShowBrowserUI(LanguageDialog, null)” type=button value=语言设置>

■前进■

<INPUT name=Submit onclick=history.go(1) type=submit value=前进>

■后退■

<INPUT name=Submit2 onclick=history.go(-1) type=submit value=后退>

急求各种网页鼠标特效代码(只要代码,不要网址)

很酷的跟随鼠标的三色彩带

html>

<head>

<title>网页特效|Linkweb.cn/Js|—很酷的跟随鼠标的三色彩带</title>

</head><body bgColor=#000000>

<!–将以下代码加入HTML的<Body></Body>之间–>

<script language=”JavaScript”>

<!–

var a_Colour='fff000';

var b_Colour='00ff00';

var c_Colour='ff00ff';

var Size=120;

var YDummy=new Array(),XDummy=new Array(),xpos=0,ypos=0,ThisStep=0;step=0.6;

if(document.layers){

window.captureEvents(Event.MOUSEMOVE);

function nsMouse(evnt){

xpos= window.pageYOffset+evnt.pageX+6;

ypos= window.pageYOffset+evnt.pageY+16;

}

window.onMouseMove= nsMouse;

}

else if(document.all)

{

function ieMouse(){

xpos= document.body.scrollLeft+event.x+6;

ypos= document.body.scrollTop+event.y+16;

}

document.onmousemove= ieMouse;

}

function swirl(){

for(i= 0; i< 3; i++)

{

YDummy[i]=ypos+Size*Math.sin((1*Math.sin((ThisStep)/10))+i*2)*Math.sin((ThisStep)/4);

XDummy[i]=xpos+Size*Math.cos((1*Math.sin((ThisStep)/10))+i*2)*Math.sin((ThisStep)/4);

}

ThisStep+=step;

setTimeout('swirl()',10);

}

var amount=10;

if(document.layers){

for(i= 0; i< amount; i++)

{

document.write('<layer name=nsa'+i+' top=0 left=0 width='+i/2+' height='+i/2+' bgcolor='+a_Colour+'></layer>');

document.write('<layer name=nsb'+i+' top=0 left=0 width='+i/2+' height='+i/2+' bgcolor='+b_Colour+'></layer>');

document.write('<layer name=nsc'+i+' top=0 left=0 width='+i/2+' height='+i/2+' bgcolor='+c_Colour+'></layer>');

}

}

else if(document.all){

document.write('<div id=”ODiv” style=”position:absolute;top:0px;left:0px”>'

+'<div id=”IDiv” style=”position:relative”>');

for(i= 0; i< amount; i++)

{

document.write('<div id=x style=”position:absolute;top:0px;left:0px;width:'+i/2+';height:'+i/2+';background:'+a_Colour+';font-size:'+i/2+'”></div>');

document.write('<div id=y style=”position:absolute;top:0px;left:0px;width:'+i/2+';height:'+i/2+';background:'+b_Colour+';font-size:'+i/2+'”></div>');

document.write('<div id=z style=”position:absolute;top:0px;left:0px;width:'+i/2+';height:'+i/2+';background:'+c_Colour+';font-size:'+i/2+'”></div>');

}

document.write('</div></div>');

}

function prepos(){

var ntscp=document.layers;

var msie=document.all;

if(document.layers){

for(i= 0; i< amount; i++)

{

if(i< amount-1)

{

ntscp['nsa'+i].top=ntscp['nsa'+(i+1)].top;ntscp['nsa'+i].left=ntscp['nsa'+(i+1)].left;

ntscp['nsb'+i].top=ntscp['nsb'+(i+1)].top;ntscp['nsb'+i].left=ntscp['nsb'+(i+1)].left;

ntscp['nsc'+i].top=ntscp['nsc'+(i+1)].top;ntscp['nsc'+i].left=ntscp['nsc'+(i+1)].left;

}

else

{

ntscp['nsa'+i].top=YDummy[0];ntscp['nsa'+i].left=XDummy[0];

ntscp['nsb'+i].top=YDummy[1];ntscp['nsb'+i].left=XDummy[1];

ntscp['nsc'+i].top=YDummy[2];ntscp['nsc'+i].left=XDummy[2];

}

}

}

else if(document.all){

for(i= 0; i<amount; i++)

{

if(i< amount-1)

{

msie.x[i].style.top=msie.x[i+1].style.top;msie.x[i].style.left=msie.x[i+1].style.left;

msie.y[i].style.top=msie.y[i+1].style.top;msie.y[i].style.left=msie.y[i+1].style.left;

msie.z[i].style.top=msie.z[i+1].style.top;msie.z[i].style.left=msie.z[i+1].style.left;

}

else

{

msie.x[i].style.top=YDummy[0];msie.x[i].style.left=XDummy[0];

msie.y[i].style.top=YDummy[1];msie.y[i].style.left=XDummy[1];

msie.z[i].style.top=YDummy[2];msie.z[i].style.left=XDummy[2];

}

}

}

setTimeout(“prepos()”,10);

}

function Start(){

swirl(),prepos()

}

window.onload=Start;

//–>

</script>

</body></html>

跟随鼠标很逼真的弹性小球

<html>

<head>

<title>网页特效|Linkweb.cn/Js|—跟随鼠标很逼真的弹性小球</title>

</head><body>

<!–将以下代码加入HTML的<Body></Body>之间–>

<DIV id=dot0

style=”HEIGHT: 16; POSITION: absolute; VISIBILITY: hidden; WIDTH: 11; left:10; top:15″><IMG

height=11 src=”images/bullet.gif” width=11></DIV>

<DIV id=dot1 style=”HEIGHT: 11px; POSITION: absolute; WIDTH: 11px”><IMG

height=11 src=”images/bullet.gif” width=11></DIV>

<DIV id=dot2 style=”HEIGHT: 11px; POSITION: absolute; WIDTH: 11px”><IMG

height=11 src=”images/bullet.gif” width=11></DIV>

<DIV id=dot3 style=”HEIGHT: 11px; POSITION: absolute; WIDTH: 11px”><IMG

height=11 src=”images/bullet.gif” width=11></DIV>

<DIV id=dot4 style=”HEIGHT: 11px; POSITION: absolute; WIDTH: 11px”><IMG

height=11 src=”images/bullet.gif” width=11></DIV>

<DIV id=dot5 style=”HEIGHT: 11px; POSITION: absolute; WIDTH: 11px”><IMG

height=11 src=”images/bullet.gif” width=11></DIV>

<DIV id=dot6 style=”HEIGHT: 16; POSITION: absolute; WIDTH: 11; left:10; top:15″><IMG

height=11 src=”images/bullet.gif” width=11></DIV>

<SCRIPT language=JavaScript>

var nDots= 7;

var Xpos= 0;

var Ypos= 0;

var DELTAT=.01;

var SEGLEN= 10;

var SPRINGK= 10;

var MASS= 1;

var XGRAVITY= 0;

var YGRAVITY= 50;

var RESISTANCE= 10;

var STOPVEL= 0.1;

var STOPACC= 0.1;

var DOTSIZE= 11;

var BOUNCE= 0.75;

var isNetscape= navigator.appName==”Netscape”;

var followmouse= true;

var dots= new Array();

init();

function init()

{

var i= 0;

for(i= 0; i< nDots; i++){

dots[i]= new dot(i);

}

if(!isNetscape){

}

for(i= 0; i< nDots; i++){

dots[i].obj.left= dots[i].X;

dots[i].obj.top= dots[i].Y;

}

if(isNetscape){

startanimate();

} else{

setTimeout(“startanimate()”, 1000);

}

}

function dot(i)

{

this.X= Xpos;

this.Y= Ypos;

this.dx= 0;

this.dy= 0;

if(isNetscape){

this.obj= eval(“document.dot”+ i);

} else{

this.obj= eval(“dot”+ i+”.style”);

}

}

function startanimate(){

setInterval(“animate()”, 20);

}

function setInitPositions(dots)

{

var startloc= document.all.tags(“LI”);

var i= 0;

for(i= 0; i< startloc.length&& i<(nDots- 1); i++){

dots[i+1].X= startloc[i].offsetLeft

startloc[i].offsetParent.offsetLeft- DOTSIZE;

dots[i+1].Y= startloc[i].offsetTop+

startloc[i].offsetParent.offsetTop+ 2*DOTSIZE;

}

dots[0].X= dots[1].X;

dots[0].Y= dots[1].Y- SEGLEN;

}

function MoveHandler(e)

{

Xpos= e.pageX;

Ypos= e.pageY;

return true;

}

function MoveHandlerIE(){

Xpos= window.event.x+ document.body.scrollLeft;

Ypos= window.event.y+ document.body.scrollTop;

}

if(isNetscape){

document.captureEvents(Event.MOUSEMOVE);

document.onMouseMove= MoveHandler;

} else{

document.onmousemove= MoveHandlerIE;

}

function vec(X, Y)

{

this.X= X;

this.Y= Y;

}

function springForce(i, j, spring)

{

var dx=(dots[i].X- dots[j].X);

var dy=(dots[i].Y- dots[j].Y);

var len= Math.sqrt(dx*dx+ dy*dy);

if(len> SEGLEN){

var springF= SPRINGK*(len- SEGLEN);

spring.X+=(dx/ len)* springF;

spring.Y+=(dy/ len)* springF;

}

}

function animate(){

var start= 0;

if(followmouse){

dots[0].X= Xpos;

dots[0].Y= Ypos;

start= 1;

}

for(i= start; i< nDots; i++){

var spring= new vec(0, 0);

if(i> 0){

springForce(i-1, i, spring);

}

if(i<(nDots- 1)){

springForce(i+1, i, spring);

}

var resist= new vec(-dots[i].dx* RESISTANCE,

-dots[i].dy* RESISTANCE);

var accel= new vec((spring.X+ resist.X)/MASS+ XGRAVITY,

(spring.Y+ resist.Y)/ MASS+ YGRAVITY);

dots[i].dx+=(DELTAT* accel.X);

dots[i].dy+=(DELTAT* accel.Y);

if(Math.abs(dots[i].dx)< STOPVEL&&

Math.abs(dots[i].dy)< STOPVEL&&

Math.abs(accel.X)< STOPACC&&

Math.abs(accel.Y)< STOPACC){

dots[i].dx= 0;

dots[i].dy= 0;

}

dots[i].X+= dots[i].dx;

dots[i].Y+= dots[i].dy;

var height, width;

if(isNetscape){

height= window.innerHeight+ window.pageYOffset;

width= window.innerWidth+ window.pageXOffset;

} else{

height= document.body.clientHeight+ document.body.scrollTop;

width= document.body.clientWidth+ document.body.scrollLeft;

}

if(dots[i].Y>=height- DOTSIZE- 1){

if(dots[i].dy> 0){

dots[i].dy= BOUNCE*-dots[i].dy;

}

dots[i].Y= height- DOTSIZE- 1;

}

if(dots[i].X>= width- DOTSIZE){

if(dots[i].dx> 0){

dots[i].dx= BOUNCE*-dots[i].dx;

}

dots[i].X= width- DOTSIZE- 1;

}

if(dots[i].X< 0){

if(dots[i].dx< 0){

dots[i].dx= BOUNCE*-dots[i].dx;

}

dots[i].X= 0;

}

dots[i].obj.left= dots[i].X;

dots[i].obj.top=dots[i].Y;

}

}

</SCRIPT>

</body></html>

这里太小了放不了那么多

里面有很多的不想链接的话就看那两个吧

关于js特效代码和炫酷的js特效代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享