论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Javascript教程
Tag:验证,特效,入门,实例,验证,表单,特效,正则表达式,跑马灯,document,函数,代码,getElementByID,菜单,图片,视频教程

javascript模拟炫光波形动画特效

文章类别:Javascript | 发表日期:2010-3-19 10:05:11

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>炫光波动效果 - Zehee</title>
<script>
var lightWave = function(T,hz,top,left,thick,sharp,particle,velocity,amplitude,opacity){
 this.cont = T;//需要添加炫光的容器
 this.hz = parseFloat(hz);//刷新率
 this.top = parseFloat(top);//炫光出生时的向下偏移量
 this.left = parseFloat(left);//炫光出生时的向右偏移量
 this.thick = parseFloat(thick);//粗细程度
 this.sharp = parseFloat(sharp);//尖锐程度
 this.particle = parseFloat(particle);//组成粒子的大小
 this.velocity = parseFloat(velocity);//波速
 this.amplitude = parseFloat(amplitude);//振幅
 this.opacity = parseFloat(opacity);//透明度
 this.cont.style.position = 'relative';
 this.move();
}
lightWave.prototype = {
 point:function(n,left,t,wavecont,color,particle){
  var p = document.createElement('p');
  p.i = left;
  p.innerHTML = '&nbsp;';
  p.style.top = t + 'px';
  p.style.left = left + 'px';
  p.style.width = particle + 'px';
  p.style.height = n + 'px';
  p.style.filter = 'alpha(opacity='+this.opacity+')';
  p.style.lineHeight = 0;
  p.style.fontSize = 0;
  p.style.position = 'absolute';
  p.style.background = color;
  wavecont.appendChild(p);
  return this;
 },
 color:function(){
  var c = ['0','3','6','9','c','f'];
  var t = [c[Math.floor(Math.random()*100)%6],'0','f'];
  t.sort(function(){return Math.random()>0.5?-1:1;});
  return '#'+t.join('');
 },
 wave:function(){
  var left = this.left,t = this.wavelength,color = this.color(),particle = this.particle,l = 0;
  var wavecont = document.createElement('div');
  wavecont.style.top = this.amplitude+this.top+'px';
  wavecont.style.left = left+'px';
  wavecont.style.position = 'absolute';
  wavecont.style.opacity = this.opacity/100;
  for(var i=1;i<this.thick;i++){
   for(var j=0;j<this.thick*this.sharp-i*i;j++,l++){
    this.point(i,l*particle,-9999,wavecont,color,particle);
   }
  }
  for(var i=this.thick;i>0;i--){
   for(var j=this.thick*this.sharp-i*i;j>0;j--,l++){
    this.point(i,l*particle,-9999,wavecont,color,particle);
   }
  }
  this.cont.appendChild(wavecont);
  return wavecont;
 },
 move:function(){
  var wl = this.amplitude;
  var velocity = this.velocity;
  var w = this.wave().getElementsByTagName('p');
  var m = function(){
   for(var i=0,len=w.length;i<len;i++){
    if(w[i].ori == true){
     w[i].i-=velocity;
     var top = w[i].i%180==90?0:wl*Math.cos(w[i].i*Math.PI/180);
     w[i].style.top = top+'px';
     if(parseFloat(w[i].style.top)<=-wl){
      w[i].ori = false;
     }
    }else{
     w[i].i+=velocity;
     var top = w[i].i%180==90?0:wl*Math.cos(w[i].i*Math.PI/180);
     w[i].style.top = top+'px';
     if(parseFloat(w[i].style.top)>=wl){
      w[i].ori = true;
     }
    }
   }
  }
  setInterval(m,this.hz);
 }
}
</script>
</head>
<body>
<div id="bar" style="font-size:12px;float:left;border:1px solid #666;padding:10px;">
<p><input id="hz" type="text" value="120" /><label>- 刷新率</label></p>
<p><input id="top" type="text" value="20" /><label>- 向下偏移量</label></p>
<p><input id="left" type="text" value="10" /><label>- 向左偏移量</label></p>
<p><input id="thick" type="text" value="3" /><label>- 粗细程度</label></p>
<p><input id="sharp" type="text" value="9" /><label>- 尖锐程度</label></p>
<p><input id="particle" type="text" value="4" /><label>- 粒子长度</label></p>
<p><input id="velocity" type="text" value="6" /><label>- 波速</label></p>
<p><input id="amplitude" type="text" value="20" /><label>- 振幅</label></p>
<p><input id="opacity" type="text" value="40" /><label>- 透明度</label></p>
<p><input type="button" value="生成" id="born" /> <input type="button" value="清除" id="clear" /></p>
</div>
<div id="waves" style="background:#000;width:600px;height:600px;float:left;margin-left:20px;dispaly:inline">&nbsp;</div>
<script>
var waves = document.getElementById('waves');
var born = document.getElementById('born');
var clear = document.getElementById('clear');
born.onclick = function(){
 var hz = document.getElementById('hz').value;
 var top = document.getElementById('top').value;
 var left = document.getElementById('left').value;
 var thick = document.getElementById('thick').value;
 var sharp = document.getElementById('sharp').value;
 var particle = document.getElementById('particle').value;
 var velocity = document.getElementById('velocity').value;
 var amplitude = document.getElementById('amplitude').value;
 var opacity = document.getElementById('opacity').value;
 new lightWave(waves,hz,top,left,thick,sharp,particle,velocity,amplitude,opacity);
}
clear.onclick = function(){window.location.reload();}
</script>
</body>
</html>

参数:
var  lightWave = function (T,hz,top,left,thick,sharp,particle,velocity,amplitude,opacity){
       this .cont = T; //需要添加炫光的容器
       this .hz = hz; //刷新率
       this .top = top; //炫光出生时的向下偏移量
       this .left = left; //炫光出生时的向右偏移量
       this .thick = thick; //粗细程度
       this .sharp = sharp; //尖锐程度
       this .particle= particle; //粒子长度
       this.velocity= velocity; //波速
       this .amplitude = amplitude; //振幅
       this .opacity = opacity; //透明度
       this .cont.style.position = 'relative';
       this .move();
}

上一篇:{教程}javascript中replace正则表达式语法 人气:2808
下一篇:深入了解Javascript 人气:2148
视频教程列表
文章教程搜索
 
Javascript推荐教程
Javascript热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058