Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Raindrop
About us
Learn More
Contact
css
html,body{ padding: 0px; margin: 0px; height: 100%; overflow: hidden; background: black; } #rain{ position: absolute; left: 0px; top: 0px; user-select: none; } h1{ text-align: center; margin-top: 130px; font-size: 42px; position: relative; color: white; } #options{ text-align: center; margin-top: 50px; position: relative; z-index: 2; } #options button{ padding: 20px; font-size: 22px; margin-left: 20px; margin-right: 20px; border-radius: 5px; cursor: pointer; background: white; border: 1px solid #95a5a6; } @media only screen and (max-width: 600px) { .raindrop:nth-child(3) { display: none; } }
JavaScript
var c = document.getElementById("rain"); c.width = window.innerWidth; c.height = window.innerHeight; var ctx = c.getContext("2d"); let rainDrops = []; let elements = document.getElementsByClassName("raindrop"); let length = 30; let speed = 15; let angle = 90 * Math.PI / 180; let angleSin = Math.sin(angle); let angleCos = Math.cos(angle); let spawnInterval = setInterval(newDrop, 50); window.addEventListener("resize", onResize); document.addEventListener("visibilitychange", function() { if (document.hidden) { clearInterval(spawnInterval); } else { spawnInterval = setInterval(newDrop, 50); } }); function RainDrop(x, y, angle) { this.x = x; this.y = y; rainDrops.push(this); } function newDrop() { for (let x = 0; x < 50; x++) { new RainDrop(Math.random() * c.width, -40 - 100 * Math.random(), angle); } } update(); function update() { for (let x = 0; x < rainDrops.length; x++) { let drop = rainDrops[x]; drop.x += speed * angleCos; drop.y += speed * angleSin; drop.endX = drop.x + length * angleCos; drop.endY = drop.y + length * angleSin; if (drop.y > c.height) { rainDrops.splice(x, 1); x--; } } //checkCollisions(); draw(); } function draw() { ctx.clearRect(0, 0, c.width, c.height); ctx.lineWidth = 1; ctx.lineCap = "round"; ctx.strokeStyle = "#0984e3"; let gradient = ctx.createLinearGradient(0, 0, 0, c.height); gradient.addColorStop(0, "#00a8ff"); gradient.addColorStop(0.6, "#00a8ff"); gradient.addColorStop(1, "white"); ctx.strokeStyle = gradient; ctx.beginPath(); for (let i = 0; i < rainDrops.length; i++) { ctx.moveTo(Math.floor(rainDrops[i].x), Math.floor(rainDrops[i].y)); ctx.lineTo(Math.floor(rainDrops[i].endX), Math.floor(rainDrops[i].endY)); } ctx.stroke(); clearRegions(); window.requestAnimationFrame(update); } function onResize() { c.width = window.innerWidth; c.height = window.innerHeight; } function clearRegions() { ctx.globalCompositeOperation = "destination-out"; for (let i = 0; i < elements.length; i++) { let boundingBox = elements[i].getBoundingClientRect(); let yDistanceBottom = c.height - boundingBox.bottom; let yDistanceTop = c.height - boundingBox.top; let bottomLeftX = boundingBox.left + yDistanceBottom * Math.tan(Math.PI / 2 - angle); let bottomRightX = boundingBox.right + yDistanceBottom * Math.tan(Math.PI / 2 - angle); let bottomLeftX2 = boundingBox.left + yDistanceTop * Math.tan(Math.PI / 2 - angle); let bottomRightX2 = boundingBox.right + yDistanceTop * Math.tan(Math.PI / 2 - angle); //From bottom of element to edge of page ctx.beginPath(); ctx.moveTo(boundingBox.left, boundingBox.bottom); ctx.lineTo(bottomLeftX, c.height); ctx.lineTo(bottomRightX, c.height); ctx.lineTo(boundingBox.right, boundingBox.bottom); ctx.closePath(); ctx.fill(); //From top of element to edge of page ctx.beginPath(); ctx.moveTo(boundingBox.left, boundingBox.top); ctx.lineTo(bottomLeftX2, c.height); ctx.lineTo(bottomRightX2, c.height); ctx.lineTo(boundingBox.right, boundingBox.top); ctx.closePath(); ctx.fill(); } ctx.globalCompositeOperation = "source-over"; }
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>canvas雨滴-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号