Can I create rain effect in javascript?

空扰寡人 提交于 2020-01-04 04:28:11

问题


I need to achieve something like this for my website: Flash Rain Effect

Is that possible to do in Javascript? I want it to be just as smooth as it is in Flash.

Another flash rain drop water effect


回答1:


Yes, it's possible: http://www.lab4games.net/zz85/blog/2010/03/10/rain-water-ripples-with-html-canvas-javascript-jquery/

Smoothness is something relative, and you may not be able to have the same performance as hardware-accelerated Flash. With that said, more and more browsers are starting to incorporate native hardware acceleration (Direct2D and otherwise).




回答2:


You should be able to do this using a combination of JavaScript and canvas elements (HTML5).




回答3:


If you don't want to use the Canvas (or can't) you can do that by creating an image that looks like a rain drop, make it a PNG with alpha transparency so the non-drop parts of the rectangle don't show up. Then you create 200 or so IMGs programmatically and position them absolutely (and randomly) over your scene. Each one gets positioned, then turned visible for a few milliseconds, then turned invisible, then rinse and repeat.

For variety you can either make images of different sizes and shades so some seem in the background and some in the foreground, and vary those.



来源:https://stackoverflow.com/questions/3027153/can-i-create-rain-effect-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!