In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to share with you the relevant knowledge points about how to achieve interesting wave effects in HTML5. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
1. Create trigger condition (button)
= "Beisizer ()" / / trigger the JS event when clicked
JS event nm mouse over JS event = "bcd ()" / /
"nm" useleave= "out ()" / / JS event when the mouse leaves
Id= "Anniu" > accurate & nbsp?     ?   & nbsp determination
2. Create a canvas Canvas
3. Create a JS event (property setting) / / get the canvas
Var?beisizer?=?document.getElementById ("Theback");? var?ContenofBeisizer?=?beisizer.getContext ("2d"); / / set wave area (wave width, height)
Var?beisizerwidth?=?beisizer.width;?var?beisizerheight?=?beisizer.height;?var?beisizerlinewidth?=?2;// curve
Var?sinX?=?0;?var?sinY?=?beisizerheight/2.0;// axis length
Var?axisLenght?=?beisizerwidth;// Radian width
Var?waveWidth?=?0.014;// wave height
Var?waveHeight?=?beisizerheight?/?15.0
ContenofBeisizer.lineWidth?=?beisizerlinewidth
4. Draw Bessel curve var?drawSin?=?function (xofspeed). {
ContenofBeisizer.save (); / / stores the points of the Bezier curve
Var?points?=? []
ContenofBeisizer.beginPath (); / / create a Bezier point
For? (var?x?=?sinX;x?
Var?y?=?-Math.sin ((sinX+x) * waveWidth+xofspeed); / /? points.push ([x _ thime). For the test, please uncomment and comment on the next line
Points.push ([x _ rem _ r _ r _ r
/ / ContenofBeisizer.lineTo, please uncomment and comment on the next line for the test
ContenofBeisizer.lineTo (x, women, girls, boys, girls, girls, boys, girls, boys, girls, boys, girls, girls, boys, girls, girls,
}
ContenofBeisizer.lineTo (axisLenght,beisizerheight)
ContenofBeisizer.lineTo (sinX,beisizerheight)
ContenofBeisizer.lineTo (points [0] [0], points [0] [1])
ContenofBeisizer.stroke ()
ContenofBeisizer.restore ();? / / Bezier curve style setting
ContenofBeisizer.strokeStyle?=? "# 3bc777"
ContenofBeisizer.fillStyle?=? "# 3bc777"
ContenofBeisizer.fill ()
This code has finished drawing the static Bessel curve, so you can try to run it by unlocking the following statement.
Var y =-Math.sin ((sinX+x) * waveWidth)
Points.push ([x _ rem _ r _ r _ r
Var y =-Math.sin ((sinX+x) * waveWidth+xofspeed)
Run the method to execute drawSin ()
Static Bezier curve. Png
5. The realization of wave effect.
You need to add the following code to the property to set the rate.
Var speed = 0.1; the higher the number, the faster the rate.
Var xofspeed = 0;? Lateral offset of waves
Var rand = beisizerheight; wave height var?rendY?=?function? {
ContenofBeisizer.clearRect / / controls the height of the waves
Var?tmp?=?0.1
Rand-=tmp;var?b?=?beisizerheight?-?rand
/ / Control of cyclic high tide
If? (parseInt (b) = = beisizerheight) {
Rand?=?beisizerheight
}
DrawSin (xofspeed)
DrawSinl (xofspeed)
Xofspeed?+=?speed
RequestAnimationFrame (rendY)
By calling itself to produce different heights, to produce a wave effect. The attribute values set here are understood together with the Bezier curve drawn in step 4.
Operation mode rendY ()
These are all the contents of the article "how to achieve interesting Wave effects in HTML5". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.