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 相关文章推荐
JQuery的ajax获取数据后的处理总结(html,xml,json)
Jul 14 Javascript
判断js对象是否拥有某一个属性的js代码
Aug 16 Javascript
jquery队列queue与原生模仿其实现方法分享
Mar 25 Javascript
百度移动版的url编码解码示例
Apr 29 Javascript
JavaScript判断undefined类型的正确方法
Jun 30 Javascript
浅析Node.js的Stream模块中的Readable对象
Jul 29 Javascript
理解javascript中的Function.prototype.bind的方法
Feb 03 Javascript
Bootstrap模态框插入视频的实现代码
Jun 25 Javascript
vue组件间通信子与父详解(二)
Nov 07 Javascript
实例详解Vue项目使用eslint + prettier规范代码风格
Aug 20 Javascript
js全屏事件fullscreenchange 实现全屏、退出全屏操作
Sep 17 Javascript
js实现3D旋转效果
Aug 18 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+mysql一个名片库程序
2006/10/09 PHP
php下实现农历日历的代码
2007/03/07 PHP
paypal即时到账php实现代码
2010/11/28 PHP
window+nginx+php环境配置 附配置搭配说明
2010/12/29 PHP
thinkPHP多语言切换设置方法详解
2016/11/11 PHP
PHP钩子与简单分发方式实例分析
2017/09/04 PHP
PHP实现chrome表单请求数据转换为接口使用的json数据
2021/03/04 PHP
js+css实现的圆角边框TAB选项卡滑动门代码分享(2款)
2015/08/26 Javascript
vue.js中$watch的用法示例
2016/10/04 Javascript
DropDownList实现可输入可选择(两种版本可选)
2016/12/07 Javascript
微信小程序 slider的简单实例
2017/04/19 Javascript
JavaScript实现提交模式窗口后刷新父窗口数据的方法
2017/06/16 Javascript
JSON在Javascript中的使用(eval和JSON.parse的区别)详细解析
2017/09/05 Javascript
详解vue-cli脚手架build目录中的dev-server.js配置文件
2017/11/24 Javascript
js的Object.assign用法示例分析
2020/03/05 Javascript
[05:48]DOTA2英雄梦之声vol21 屠夫
2014/06/20 DOTA
在Python中操作日期和时间之gmtime()方法的使用
2015/05/22 Python
python制作花瓣网美女图片爬虫
2015/10/28 Python
使用Python将数组的元素导出到变量中(unpacking)
2016/10/27 Python
各种Python库安装包下载地址与安装过程详细介绍(Windows版)
2016/11/02 Python
Python 出现错误TypeError: ‘NoneType’ object is not iterable解决办法
2017/01/12 Python
mac安装pytorch及系统的numpy更新方法
2018/07/26 Python
Python Scapy随心所欲研究TCP协议栈
2018/11/20 Python
线程安全及Python中的GIL原理分析
2019/10/29 Python
Python 切分数组实例解析
2019/11/07 Python
python爬虫如何解决图片验证码
2021/02/14 Python
英国设计师泳装、沙滩装和比基尼在线精品店:Beach Cafe
2019/08/28 全球购物
Jack Rogers官网:美国经典的女性鞋靴品牌
2019/09/04 全球购物
幼儿园教师个人反思
2014/01/30 职场文书
家长建议怎么写
2014/05/15 职场文书
卫生标语大全
2014/06/21 职场文书
学习焦裕禄同志为人民服务思想汇报
2014/09/10 职场文书
银行贷款收入证明
2014/10/17 职场文书
2015小学语文教师个人工作总结
2015/05/20 职场文书
vue实力踩坑之push当前页无效
2022/04/10 Vue.js
图神经网络GNN算法
2022/05/11 Python