JavaScript实现Flash炫光波动特效


Posted in Javascript onMay 14, 2015

看到flash的实现这类的动画非常的便捷,于是试图胡搞一下。全部是用dom模拟的像素点,锯齿是难免的……

这个要避免锯齿恐怕要再加一次滤镜了吧,或者用图片。

<!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>
<title>炫光波动效果</title>
<script>
var lightWave = function(T,left,thick,sharp,speed,vibration,amplitude,opacity){
this.cont = T;//炫光容器
this.left = left;//炫光向右偏移量
this.thick = thick;//粗细
this.sharp = sharp;//尖锐度
this.speed = speed;//波动速度
this.vibration = vibration;//单位时间内的振动频率
this.amplitude = amplitude;//振幅
this.opacity = opacity;//透明度
this.cont.style.position = 'relative';
this.move();
}
lightWave.prototype = {
point:function(n,l,t,c,color){
var p = document.createElement('p');
p.innerHTML = ' ';
p.style.top = t + 'px';
p.style.left = l + 'px';
p.style.width = 1 + 'px';
p.style.height = n + 'px';
p.style.filter = 'alpha(opacity='+this.opacity+')';
p.style.lineHeight = 0;
p.style.position = 'absolute';
p.style.background = color;
c.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 l = this.left,t = this.wavelength,color = this.color();
var c = document.createElement('div');
c.style.top = this.amplitude+20+'px';
c.style.position = 'absolute';
c.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,-9999,c,color);
}
}
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,-9999,c,color);
}
}
this.cont.appendChild(c);
return c;
},
move:function(){
var wl = this.amplitude;
var vibration = this.vibration;
var w = this.wave().getElementsByTagName('p');
for(var i=0;i<w.length;i++){
w[i].i = i;
}
var m = function(){
for(var i=0,len=w.length;i<len;i++){
if(w[i].ori == true){
w[i].i-=vibration;
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+=vibration;
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.speed);
}
}
window.onload = function(){
var targetDom = document.body;
new lightWave(targetDom,0,3,36,120,6,20,40);
new lightWave(targetDom,50,2,70,120,10,30,30);
}
</script>
</head>
<body style="background:#000;margin-top:100px">
</body>
</html>

参数:

var lightWave = function (T,left,thick,sharp,speed,vibration,amplitude,opacity){
    this .cont = T; //需要添加炫光的容器
    this .left = left; //炫光出生时的向右偏移量
    this .thick = thick; //粗细程度
    this .sharp = sharp; //尖锐程度
    this .speed = speed; //波动速度
    this.vibration = vibration; //单位时间内的振动频率
    this .amplitude = amplitude; //振幅
    this .opacity = opacity; //透明度
    this .cont.style.position = 'relative';
    this .move();
}

大家感兴趣可以来讨论一下。

另外,还遇到个问题,上面代码中ie下面的透明度滤镜不起作用,经研究得知,改变父容器的定位会影响子节点的透明滤镜的继承。

以上所述就是本文的全部内容了,希望大家能够喜欢。

Javascript 相关文章推荐
toString()一个会自动调用的方法
Feb 08 Javascript
jQuery实现页面滚动时层智能浮动定位实例探讨
Mar 29 Javascript
Js,alert出现乱码问题的解决方法
Jun 19 Javascript
Bootstrap每天必学之导航条(二)
Mar 01 Javascript
浅谈js里面的InttoStr和StrtoInt
Jun 14 Javascript
详解ECharts使用心得总结
Dec 06 Javascript
谈谈第三方App接入微信登录 解读
Dec 27 Javascript
js实现控制文件拖拽并获取拖拽内容功能
Feb 17 Javascript
vue对storejs获取的数据进行处理时遇到的几种问题小结
Mar 20 Javascript
vue-router中的hash和history两种模式的区别
Jul 17 Javascript
微信小程序使用component自定义toast弹窗效果
Nov 27 Javascript
基于layui的下拉列表的数据回显方法
Sep 24 Javascript
javascript基于DOM实现省市级联下拉框的方法
May 14 #Javascript
javascript搜索框效果实现方法
May 14 #Javascript
javascript操作ul中li的方法
May 14 #Javascript
javascript中createElement的两种创建方式
May 14 #Javascript
javascript常用方法总结
May 14 #Javascript
javascript实现动态改变层大小的方法
May 14 #Javascript
JavaScript中停止执行setInterval和setTimeout事件的方法
May 14 #Javascript
You might like
PHP文本数据库的搜索方法
2006/10/09 PHP
GD输出汉字的函数的分析
2006/10/09 PHP
用php获取远程图片并把它保存到本地的代码
2008/04/07 PHP
php xfocus防注入资料
2008/04/27 PHP
php基础设计模式大全(注册树模式、工厂模式、单列模式)
2015/08/31 PHP
thinkphp5实现无限级分类
2019/02/18 PHP
jquery select选中的一个小问题
2009/10/11 Javascript
jquery validate使用攻略 第四步
2010/07/01 Javascript
jQuery.query.js 取参数的两点问题分析
2012/08/06 Javascript
js自动闭合html标签(自动补全html标记)
2012/10/04 Javascript
快速解决jquery之get缓存问题的最简单方法介绍
2013/12/19 Javascript
js判断60秒以及倒计时示例代码
2014/01/24 Javascript
javascript中取前n天日期的两种方法分享
2014/01/26 Javascript
js写的方法实现上传图片之后查看大图
2014/03/05 Javascript
jQuery中的jQuery()方法用法分析
2014/12/27 Javascript
JQuery替换DOM节点的方法
2015/06/11 Javascript
Wireshark基本介绍和学习TCP三次握手
2016/08/15 Javascript
Bootstrap table两种分页示例
2016/12/23 Javascript
JS实现预加载视频音频/视频获取截图(返回canvas截图)
2017/10/09 Javascript
js 显示日期时间的实例(时间过一秒加1)
2017/10/25 Javascript
利用原生js实现html5小游戏之打砖块(附源码)
2018/01/03 Javascript
[01:12]快闪回顾DOTA2亚洲邀请赛(DAC) 静候2018新征程开启
2018/03/11 DOTA
linux系统使用python获取cpu信息脚本分享
2014/01/15 Python
python使用Image处理图片常用技巧分析
2015/06/01 Python
基于Python实现的ID3决策树功能示例
2018/01/02 Python
python+pillow绘制矩阵盖尔圆简单实例
2018/01/16 Python
使用python 打开文件并做匹配处理的实例
2019/01/02 Python
PyTorch的SoftMax交叉熵损失和梯度用法
2020/01/15 Python
Python如何使用OS模块调用cmd
2020/02/27 Python
python实现文件分片上传的接口自动化
2020/11/19 Python
美国最大网上鞋店:Zappos
2016/07/25 全球购物
Grow Gorgeous美国官网:只要八天,体验唤醒毛囊后新生的茂密秀发
2018/06/04 全球购物
音乐教学案例
2014/01/30 职场文书
法学专业求职信
2014/07/15 职场文书
2015年社区民政工作总结
2015/04/21 职场文书
QT与javascript交互数据的实现
2021/05/26 Javascript