Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body { height: 100%; width: 100%; overflow: hidden; background-color: #0A0326; padding: 0; margin: 0; }
JavaScript
var trees = []; let stars = []; const svg = document.getElementById("svg"); let w = window.innerWidth; let h = window.innerHeight; svg.style.width = w; svg.style.height = h; var colors = [ "#C501E1", "#9A26F8", "#6564FE", "#2B97FA", "#02C4E7", "#16E6CC", "#2EF9A0", "#C6E501", "#E7C501", "#FF6A63", "#F82D98", "#E830CE" ]; //update svg dimension on window resize window.addEventListener("resize", function(e) { w = svg.style.width = window.innerWidth; h = svg.style.height = window.innerHeight; createScenery(); }); class Star { constructor(x, y, r) { this.x = x; this.y = y; this.r = r; this.color = colors[Math.floor(Math.random() * colors.length)]; this.opacity = Math.random() + 0.2; this.starEl = document.createElementNS( "http://www.w3.org/2000/svg", "circle" ); this.starEl.setAttribute("fill", this.color); this.starEl.setAttribute("cx", this.x); this.starEl.setAttribute("cy", this.y); } updatePath() { this.starEl.setAttribute("fill-opacity", this.opacity); this.starEl.setAttribute("r", this.r); } animate() { var time = 2; var delay = Math.random(); TweenLite.to(this, time, { r: this.r + 1, opacity: Math.random(), ease: Bounce.easeOut, delay: delay, onUpdate: () => this.updatePath(), onComplete: () => TweenLite.to(this, time, { r: this.r - 1, opacity: Math.random() + 0.2, ease: Bounce.easeOut, delay: delay, onUpdate: () => this.updatePath(), onComplete: () => this.animate() }) }); } } const createStars = () => { stars = []; while (svg.firstChild) { svg.removeChild(svg.firstChild); } for (var i = 0; i < 100; i++) { var x = Math.random() * w; var y = Math.random() * h; var r = Math.ceil(Math.random() * 4) + 1; var star = new Star(x, y, r); stars.push(star); star.updatePath(); svg.appendChild(star.starEl); star.animate(); } }; class Moon { constructor(x, y, r) { this.x = x; this.y = y; this.r = r; this.x2 = this.r * 2; this.y2 = this.r * 2; this.moonEl = document.createElementNS( "http://www.w3.org/2000/svg", "path" ); this.moonEl.setAttribute("fill", "white"); } updatePath() { this.moonEl.setAttribute( "d", `M${this.x},${this.y} a1,1 0 0,0 ${this.x2},${this.y2}` ); } animate() { var time = 2; TweenLite.to(this, time, { y2: -this.y2, y: this.y + this.r * 2, ease: Bounce.easeOut, delay: 5, onUpdate: () => this.updatePath(), onComplete: () => TweenLite.to(this, time, { y2: this.r * 2, y: this.y - this.r * 2, ease: Bounce.easeOut, delay: 5, onUpdate: () => this.updatePath(), onComplete: () => this.animate() }) }); } } const createMoon = () => { var x = Math.floor(Math.random() * w / 2) + 100; var y = Math.floor(Math.random() * h / 8) + 50; var r = 50; var moon = new Moon(x, y, r); moon.updatePath(); svg.appendChild(moon.moonEl); moon.animate(); }; class Tree { constructor(x1, x2, y1, y2, color) { this.x1 = x1; this.x2 = x2; this.y1 = y1; this.y2 = y2; this.color = color; this.offset = 2; this.point = 0; this.size = 45; this.lineEl = document.createElementNS( "http://www.w3.org/2000/svg", "line" ); this.lineEl.setAttribute("stroke-linecap", "round"); this.lineEl.setAttribute("stroke", this.color); this.lineEl.setAttribute("stroke-width", 12); this.lineEl.setAttribute("y1", this.y1); this.lineEl.setAttribute("x1", this.x1); this.lineEl.setAttribute("x2", this.x2); this.triangleEl = document.createElementNS( "http://www.w3.org/2000/svg", "polygon" ); this.triangleEl.setAttribute("fill", this.color); this.triangleEl2 = document.createElementNS( "http://www.w3.org/2000/svg", "polygon" ); this.triangleEl2.setAttribute("fill", this.color); this.triangleEl3 = document.createElementNS( "http://www.w3.org/2000/svg", "polygon" ); this.triangleEl3.setAttribute("fill", this.color); } updatePath() { this.lineEl.setAttribute("y2", this.y2); this.triangleEl.setAttribute( "points", `${this.x1},${this.y2 - this.offset * this.size} ${this.x1 + this.size},${this.y2 - this.point} ${this.x1 - this.size},${this.y2 - this.point}` ); this.triangleEl2.setAttribute( "points", `${this.x1},${this.y2 - (this.offset + 0.5) * this.size} ${this.x1 + this.size},${this.y2 - (this.point + 30)} ${this.x1 - this.size},${this .y2 - (this.point + 30)}` ); this.triangleEl3.setAttribute( "points", `${this.x1},${this.y2 - (this.offset + 1) * this.size} ${this.x1 + this.size},${this.y2 - (this.point + 60)} ${this.x1 - this.size},${this .y2 - (this.point + 60)}` ); } animate() { var delay = Math.random() + 0.8; var time = 2 + Math.random() * 1.2; TweenLite.to(this, time, { y2: h - (Math.random() * 200) - 50, ease: Bounce.easeOut, delay: delay, onUpdate: () => this.updatePath(), //update our path data onComplete: () => TweenLite.to(this, time, { y2: h / 2 - (Math.random() * 250) + 100, ease: Bounce.easeOut, delay: delay, onUpdate: () => this.updatePath(), onComplete: () => this.animate() }) }); } } const createTrees = () => { trees = []; var c = 0; for (var i = 5; i < w / 10; i += 10) { var color = colors[c]; var width = 12; var x1 = i * 10; var x2 = x1; var y1 = h; var y2 = Math.floor(Math.random() * (h / 2)) + 200; var tree = new Tree(x1, x2, y1, y2, color); if (c === colors.length - 1) { c = 0; } else { c++; } trees.push(tree); tree.updatePath(); svg.appendChild(tree.lineEl); svg.appendChild(tree.triangleEl); svg.appendChild(tree.triangleEl2); if (i % 3 !== 0) { svg.appendChild(tree.triangleEl3); } tree.animate(); } }; const createScenery = () => { createStars(); createMoon(); createTrees(); }; createScenery();
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>迷人的森林(SVG + GSAP)-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号