html动态特效(html代码生成图片)
大家好,今天来为大家解答html动态特效这个问题的一些问题点,包括html代码生成图片也一样很多人还不知道,因此呢,今天就来为大家分析分析,现在让我们一起来看看吧!如果解决了您的问题,还望您关注下本站哦,谢谢~
HTML5动画特效怎么做
主要思想:
首先要准备一张有连续帧的图片,然后利用HTML5 Canvas的draw方法在不同的时间间隔绘制不同的帧,这样看起来就像动画在播放。
关键技术点:
JavaScript函数setTimeout()有两个参数,第一个是参数可以传递一个JavaScript方法,
另外一个参数代表间隔时间,单位为毫秒数。代码示例:
setTimeout( update, 1000/30);
Canvas的API-drawImage()方法,需要指定全部9个参数:
ctx.drawImage(myImage, offw, offh, width,height, x2, y2, width, height);
其中offw, offh是指源图像的起始坐标点,width, height表示源图像的宽与高,x2,y2表
示源图像在目标Canvas上的起始坐标点。
<!DOCTYPEhtml>
<html>
<head>
<metahttp-equiv="X-UA-Compatible"content="chrome=IE8">
<metahttp-equiv="Content-type"content="text/html;charset=UTF-8">
<title>CanvasMouseEventDemo</title>
<linkrel="external nofollow" href="default.css"rel="stylesheet"/>
<script>
varctx=null;//globalvariable2dcontext
varstarted=false;
varmText_canvas=null;
varx=0,y=0;
varframe=0;//225*5+2
varimageReady=false;
varmyImage=null;
varpx=300;
varpy=300;
varx2=300;
vary2=0;
window.onload=function(){
varcanvas=document.getElementById("animation_canvas");
console.log(canvas.parentNode.clientWidth);
canvas.width=canvas.parentNode.clientWidth;
canvas.height=canvas.parentNode.clientHeight;
if(!canvas.getContext){
console.log("Canvasnotsupported.PleaseinstallaHTML5compatiblebrowser.");
return;
}
//get2Dcontextofcanvasanddrawrectangel
ctx=canvas.getContext("2d");
ctx.fillStyle="black";
ctx.fillRect(0,0,canvas.width,canvas.height);
myImage=document.createElement('img');
myImage.src="../robin.png";
myImage.onload=loaded();
}
functionloaded(){
imageReady=true;
setTimeout(update,1000/30);
}
functionredraw(){
ctx.clearRect(0,0,460,460)
ctx.fillStyle="black";
ctx.fillRect(0,0,460,460);
//findtheindexofframesinimage
varheight=myImage.naturalHeight/5;
varwidth=myImage.naturalWidth/5;
varrow=Math.floor(frame/5);
varcol=frame-row*5;
varoffw=col*width;
varoffh=row*height;
//firstrobin
px=px-5;
py=py-5;
if(px<-50){
px=300;
}
if(py<-50){
py=300;
}
//varrate=(frame+1)/22;
//varrw=Math.floor(rate*width);
//varrh=Math.floor(rate*height);
ctx.drawImage(myImage,offw,offh,width,height,px,py,width,height);
//secondrobin
x2=x2-5;
y2=y2+5;
if(x2<-50){
x2=300;
y2=0;
}
ctx.drawImage(myImage,offw,offh,width,height,x2,y2,width,height);
}
functionupdate(){
redraw();
frame++;
if(frame>=22)frame=0;
setTimeout(update,1000/30);
}
</script>
</head>
<body>
<h1>HTMLCanvasAnimationsDemo-ByGloomyFish</h1>
<pre>PlayAnimations</pre>
<divid="my_painter">
<canvasid="animation_canvas"></canvas>
</div>
</body>
</html>
怎么给html5背景加上js粒子特效
使用了particles.js
particles.js可以从github网站下载到最新的源码,网址是
使用方法非常简单
第一步,在html中引入脚本文件 particles.min.js,这个文件在下载的压缩包里可以找到
<scriptsrc="particles.min.js"></script>第二步,在html中放入一个div容器,设置id为particles-js。这个一般放在所有网页元素的最后面就可以。
<divid="particles-js"></div>
<styletype="text/css">
#particles-js{
position:absolute;
top:0;
width:100%;
}
</style>第三步,设置窗口样式
<styletype="text/css">
#particles-js{
z-index:-1;
position:absolute;
top:0;
width:100%;
background:#aaa;
}</style>第四步,脚本生成粒子效果,可以单独放在一个js文件里,也可以放在<script>标签里。无论如何,这段脚本要出现在div容器之后。
particlesJS("particles-js",{"particles":{"number":{"value":380,"density":{"enable":true,"value_area":800
}
},"color":{"value":"#ffffff"
},"shape":{"type":"circle","stroke":{"width":0,"color":"#000000"
},"polygon":{"nb_sides":5
},"image":{"src":"img/github.svg","width":100,"height":100
}
},"opacity":{"value":0.5,"random":false,"anim":{"enable":false,"speed":1,"opacity_min":0.1,"sync":false
}
},"size":{"value":3,"random":true,"anim":{"enable":false,"speed":40,"size_min":0.1,"sync":false
}
},"line_linked":{"enable":true,"distance":150,"color":"#ffffff","opacity":0.4,"width":1
},"move":{"enable":true,"speed":6,"direction":"none","random":false,"straight":false,"out_mode":"out","bounce":false,"attract":{"enable":false,"rotateX":600,"rotateY":1200
}
}
},"interactivity":{"detect_on":"canvas","events":{"onhover":{"enable":true,"mode":"grab"
},"onclick":{"enable":true,"mode":"push"
},"resize":true
},"modes":{"grab":{"distance":140,"line_linked":{"opacity":1
}
},"bubble":{"distance":400,"size":40,"duration":2,"opacity":8,"speed":3
},"repulse":{"distance":200,"duration":0.4
},"push":{"particles_nb":4
},"remove":{"particles_nb":2
}
}
},"retina_detect":true});
如何制作动态网页
动态网页是个广泛的提法,严格意义上是需要基于动态环境的。比如ASP、PHP等环境!可以实现在线动态更新、在线上传(不是用FTP,密码上传)等功能。没有这个环境,用什么工具都不会实现留言簿、论坛的制作。
有了这个环境,你就可以Dreamweaver MX、Flash MX、Firwork MX等等软件结合能实现跑来跑去的小人或动态链接等特效的JAVA、VB脚本等语言编程制作真正意义上的动态网页。
动态离不开静态,一些LOGO等动态图片(GIF格式)都是基于最基本的PHOTOSHOP工具制作出来的。有了一系列的静态图片,结合网上一些小GIF制作软件就可以实现动态图片了。
真正的动态,别人知道不知道无所谓,关键是自己肯定能感受到。他会让你更新网页的工作变的很枯燥,也会因为不能和网友互动信息使你懊恼异常……
总知:动态基于静态,通过软件把静态部分处理好,就可以用编程实现动态网页的制作了还是先学习一些网页脚本语言吧,然后学习asp,就知道制作动态网页和网站.不过现在用软件来设计很简洁方便.
自己可以找些相关的书或去相关的网站看看.没有一定的基础是不容易掌握动态网页和网站制作的.
顺便推荐你来这里学习动态网页的制作教程,可以详细的学习初中高等级别的知识
好了,文章到此结束,希望可以帮助到大家。