js点击鼠标产生树叶飞舞落下动画效果代码
代码语言:html
所属分类:动画
代码描述:js点击鼠标产生树叶飞舞落下动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> @import url('https://fonts.googleapis.com/css?family=Montserrat:700'); html { box-sizing: border-box; user-select: none; } *, *:before, *:after { box-sizing: inherit; } body { background-color: rgb(243, 241, 241); text-align: center; position: relative; overflow: hidden; color: #014c45; } h1 { padding: 1em; border: 5px solid; font-family: 'Montserrat', sans-serif; position: absolute; top: 150px; left: 50%; transform: translateX(-50%); text-transform: uppercase; opacity: 0.6; } .normal-fade { animation: fade 5s forwards; } .counter-fade { animation: fade-counter 4s forwards; } @keyframes fade { 0% { opacity: 1; } 2% { transform: scale(1.3); } 100%{ opacity: 0; transform: translateY(1000px) scale(0.5) rotate(200deg); } } @keyframes fade-counter { 0% { opacity: 1; } 2% { transform: scale(0.5); } 100%{ opacity: 0; transform: translateY(1000px) scale(1) rotate(-300deg); } } </style> </head> <body > <h1>🍀☘ Click / tap anywhere for shamrocks! ☘🍀</h1> <script> document.addEventListener('click', showShamrock); function showShamrock(event){ var posX = event.pageX; var posY = event.pageY; createShamrock(posX, posY, randomShamrock(), randomClass(), randomGreen()); var svgs = document.getElementsByTagName('svg'); if(svgs.length > 50){ for (i = svgs.length - 1; i >= 0; i--) { svgs[i].parentNode.removeChild(svgs[i]); } } } function randomGreen(){ var greens = ['#66a841', '#7ba237', '#95eb00', '#00b842', '#4caf50', '#56B949', '#C1CCAE', '#03d1ab', '#8DC0B1', '#B2EDCE', '#88C542', '#a6cb62', '#47cb4a', '#9BF14F', '#6b7d27', '#4caf50', '#00be70', '#207720', '#86c036']; var random = Math.floor(Math.random() * (greens.length - 1 + 1)) + 0; var green = greens[random]; // console.log(random, green); return green; } function randomClass(){ var animClass = ['normal-fade','counter-fade']; var random = Math.floor(Math.random() * (animClass.length - 1 + 1)) + 0; return animClass[random]; } function random.........完整代码请登录后点击上方下载按钮下载查看
网友评论0