国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

JavaScript實現Flash炫光波動特效

2024-05-06 16:20:13
字體:
來源:轉載
供稿:網友

JavaScript寫的炫光波動效果,看到一些Flash效果不錯,用JS也模擬一下,還有很多不完善的地方,給各位參考參考。

看到flash的實現這類的動畫非常的便捷,于是試圖胡搞一下。全部是用dom模擬的像素點,鋸齒是難免的……

這個要避免鋸齒恐怕要再加一次濾鏡了吧,或者用圖片。

 

 
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
  2. <html xmlns="http://www.w3.org/1999/xhtml"
  3. <head> 
  4. <title>炫光波動效果</title> 
  5. <script> 
  6. var lightWave = function(T,left,thick,sharp,speed,vibration,amplitude,opacity){ 
  7. this.cont = T;//炫光容器 
  8. this.left = left;//炫光向右偏移量 
  9. this.thick = thick;//粗細 
  10. this.sharp = sharp;//尖銳度 
  11. this.speed = speed;//波動速度 
  12. this.vibration = vibration;//單位時間內的振動頻率 
  13. this.amplitude = amplitude;//振幅 
  14. this.opacity = opacity;//透明度 
  15. this.cont.style.position = 'relative'
  16. this.move(); 
  17. lightWave.prototype = { 
  18. point:function(n,l,t,c,color){ 
  19. var p = document.createElement('p'); 
  20. p.innerHTML = ''
  21. p.style.top = t + 'px'
  22. p.style.left = l + 'px'
  23. p.style.width = 1 + 'px'
  24. p.style.height = n + 'px'
  25. p.style.filter = 'alpha(opacity='+this.opacity+')'
  26. p.style.lineHeight = 0; 
  27. p.style.position = 'absolute'
  28. p.style.background = color; 
  29. c.appendChild(p); 
  30. return this
  31. }, 
  32. color:function(){ 
  33. var c = ['0','3','6','9','c','f']; 
  34. var t = [c[Math.floor(Math.random()*100)%6],'0','f']; 
  35. t.sort(function(){return Math.random()>0.5?-1:1;}); 
  36. return '#'+t.join(''); 
  37. }, 
  38. wave:function(){ 
  39. var l = this.left,t = this.wavelength,color = this.color(); 
  40. var c = document.createElement('div'); 
  41. c.style.top = this.amplitude+20+'px'
  42. c.style.position = 'absolute'
  43. c.style.opacity = this.opacity/100; 
  44. for(var i=1;i<this.thick;i++){ 
  45. for(var j=0;j<this.thick*this.sharp-i*i;j++,l++){ 
  46. this.point(i,l,-9999,c,color); 
  47. for(var i=this.thick;i>0;i--){ 
  48. for(var j=this.thick*this.sharp-i*i;j>0;j--,l++){ 
  49. this.point(i,l,-9999,c,color); 
  50. this.cont.appendChild(c); 
  51. return c; 
  52. }, 
  53. move:function(){ 
  54. var wl = this.amplitude; 
  55. var vibration = this.vibration; 
  56. var w = this.wave().getElementsByTagName('p'); 
  57. for(var i=0;i<w.length;i++){ 
  58. w[i].i = i; 
  59. var m = function(){ 
  60. for(var i=0,len=w.length;i<len;i++){ 
  61. if(w[i].ori == true){ 
  62. w[i].i-=vibration; 
  63. var top = w[i].i%180==90?0:wl*Math.cos(w[i].i*Math.PI/180); 
  64. w[i].style.top = top+'px'
  65. if(parseFloat(w[i].style.top)<=-wl){ 
  66. w[i].ori = false
  67. }else
  68. w[i].i+=vibration; 
  69. var top = w[i].i%180==90?0:wl*Math.cos(w[i].i*Math.PI/180); 
  70. w[i].style.top = top+'px'
  71. if(parseFloat(w[i].style.top)>=wl){ 
  72. w[i].ori = true
  73. setInterval(m,this.speed); 
  74. window.onload = function(){ 
  75. var targetDom = document.body; 
  76. new lightWave(targetDom,0,3,36,120,6,20,40); 
  77. new lightWave(targetDom,50,2,70,120,10,30,30); 
  78. </script> 
  79. </head> 
  80. <body style="background:#000;margin-top:100px"
  81. </body> 
  82. </html> 

參數:

 

 
  1. var lightWave = function (T,left,thick,sharp,speed,vibration,amplitude,opacity){ 
  2. this .cont = T; //需要添加炫光的容器 
  3. this .left = left; //炫光出生時的向右偏移量 
  4. this .thick = thick; //粗細程度 
  5. this .sharp = sharp; //尖銳程度 
  6. this .speed = speed; //波動速度 
  7. this.vibration = vibration; //單位時間內的振動頻率 
  8. this .amplitude = amplitude; //振幅 
  9. this .opacity = opacity; //透明度 
  10. this .cont.style.position = 'relative'
  11. this .move(); 

大家感興趣可以來討論一下。

另外,還遇到個問題,上面代碼中ie下面的透明度濾鏡不起作用,經研究得知,改變父容器的定位會影響子節點的透明濾鏡的繼承。

以上所述就是本文的全部內容了,希望大家能夠喜歡。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 郓城县| 城步| 平阴县| 名山县| 稻城县| 抚远县| 桦甸市| 云林县| 怀化市| 长丰县| 独山县| 望都县| 金坛市| 东平县| 庆云县| 南康市| 漾濞| 无极县| 堆龙德庆县| 永顺县| 岱山县| 伊春市| 张掖市| 格尔木市| 和平县| 木里| 洪洞县| 南城县| 新泰市| 丰都县| 新乐市| 柳河县| 监利县| 文昌市| 济源市| 湛江市| 金门县| 麻栗坡县| 象州县| 岱山县| 绍兴市|