宇宙行星公转粒子效果
代码语言:html
所属分类:粒子
代码描述:宇宙行星公转粒子效果
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> body { background: #d8e8e3; font-family: Trebuchet MS,Lucida Grande,Lucida Sans Unicode,Lucida Sans,Tahoma, sans-serif; padding: 200px 20px 800px; max-width: 600px; margin: auto; } .screen-reader { clip: rect(1px, 1px, 1px, 1px); position: absolute !important; height: 1px; width: 1px; overflow: hidden; } .screen-reader:focus { background-color: #ddd; border-radius: 3px; box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.6); clip: auto !important; color: #444; display: block; font-size: 1.2rem; font-weight: bold; height: auto; left: 5px; line-height: normal; padding: 15px 23px 14px; text-decoration: none; top: 5px; width: auto; z-index: 100000; /* Above WP toolbar. */ } #field, .field-info-container { background: #eee; position: absolute; width: 200px; height: 200px; border-radius: 50%; margin: auto; top: 250px; left: 40%; } .field-info-container { position: absolute; display: -webkit-box; display: flex; -webkit-box-pack: center; justify-content: center; -webkit-box-align: center; align-items: center; text-align: center; -webkit-box-orient: vertical; -webkit-box-direction: normal; flex-direction: column; background: #fff; box-shadow: 0 1px 15px rgba(255, 255, 255, 0.8); z-index: 5; top: 0; left: 0; } .field-info-container:after, .field-info-container:before { display: block; content: ''; position: absolute; width: 200%; height: 200%; border: 2px solid #fff; border-radius: 50%; } .field-info-container:before { width: 350%; height: 350%; border: 2px solid rgba(255, 255, 255, 0.5); } .ball { position: absolute; border-radius: 50%; width: 10px; height: 10px; background: #0ebeff; } button { float: left; border: none; background: #fff; width: 50px; height: 50px; font-size: 20px; font-weight: bold; border-radius: 50%; cursor: pointer; color: #0ebeff; display: -webkit-box; display: flex; -webkit-box-pack: center; justify-content: center; -webkit-box-align: center; align-items: center; -webkit-box-orient: horizontal; -webkit-box-direction: normal; flex-direction: row; margin-right: 10px; -webkit-transition: all .15s ease-out; transition: all .15s ease-out; } button:hover { -webkit-transform: scale(1.15); transform: scale(1.15); } .decrease-pull { margin-top: 4px; width: 42px; height: 42px; } .decrease-pull:hover { -webkit-transform: scale(0.9); transform: scale(0.9); } button:hover, button:focus { outline: none; box-shadow: 0 0 2px #0ebeff; } .current-pull { font-size: 40px; position: relative; } .percentage-sign { font-size: 15px; position: absolute; top: 5px; } .gravity-form { position: relative; z-index: 99; } button:disabled { color: #ccc; opacity: 0.7; } </style> </head> <body translate="no"> <form class="gravity-form"> <span class="screen-reader">Set Pull</span> <button type="button" id="decrease-pull" class="decrease-pull"><span class="screen-reader">Decrease Pull</span>-</button> <button type="button" id="increase-pull" class="increase-pull"><span class="screen-reader">Increase Pull</span>+</button> </form> <div id="field"> <div id="balls"></div> <div class="field-info-container" aria-live="polite"> <div class="field-info"> <h3>Current Pull</h3> <p class="current-pull"> <span id="current-gravity"></span> <span class="percentage-sign">%</span> </p> </div> </div> </div> <script> // Original JavaScript code by Chirp Internet: www.chirp.com.au // Please acknowledge use of this code by including this header. // Modified very, very heavily by Jeremy Jones: https://jeremyjon.es const numberOfBalls = 80; const minSize = 4; const maxSize = 18; const colors = [ '#0ebeff', '#0ebeff', // I want more of the blue ones '#59C9A5', '#EDCA04']; class Orbit { constructor() { this.field = document.getElementById('field'); this.ballsEl = document.getElementById('balls'); this.gravitationalPull = 50; this.gravityText = document.getElementById('current-gravity'); this.increasePullBtn = document.getElementById('increase-pull'); this.decreasePullBtn = document.getElementById('decrease-pull'); this.balls = null; this.ballSettings = { num: numberOfBalls, minSize: minSize, maxSize: maxSize }; this.start = 0; this.init(40); } init(ballsNum) { this.balls = this.createBalls(ballsNum); window.requestAnimationFrame(this.step.bind(this)); this.setPullButtons(this.gravitationalPull); this.increasePullBtn.addEventListener('click', this.increaseGravitationalPull.bind(this)); this.decreasePullBtn.addEventListener('click', this.decreaseGravitationalPull.bind(this)); // uncomment to have planet track cursor // document.onmousemove = getCursorXY; } createBalls() { let size; for (let i = 0; i < this.ballSettings.num; i++) { // get random size between setting sizes size = Math.ceil(this.ballSettings.minSize + Math.random() * (this.ballSettings.maxSize - this.ballSettings.minSize)); this.createBall(size); } // return all the balls .........完整代码请登录后点击上方下载按钮下载查看
网友评论0