비전공자 개발일기

Abstract BG Generator with anime.js 본문

HTML _CSS

Abstract BG Generator with anime.js

HiroDaegu 2022. 10. 25. 00:22
728x90
SMALL

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ABSTRACT BG GENERATOR</title>
    <link rel="stylesheet" href="style.css">
    <script defer src="main.js"></script>
    <script src="anime.min.js"></script>
</head>
<body>
    <div class="container">
        <button class="btnAni">Generate</button>
    </div>
</body>
</html>
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #202020;
    overflow: hidden;
}
.container {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

button {
    position: relative;
    z-index: 1;
    margin: 10px;
    border: none;
    outline: none;
    background-color: #FFF;
    font-size: 1.2em;
    padding: 15px 30px;
    cursor: pointer;
    box-shadow: 10px 10px 30px rgba(0, 0, 0, .25);
    /* display: none; */
}

.block {
    position: absolute;
    width: 50px;
    height: 50px;
    background-color: #FFF;
    box-shadow: 10px 10px 30px rgba(0, 0, 0, .25);
}

.block:nth-child(3n + 2) {
     background-color: #444;
}

.block:nth-child(3n + 3) {
     background-color: #FF9213;
}
const container = document.querySelector(".container");
for (let i = 1; i <= 100; i++) {
  const blocks = document.createElement("div");
  blocks.classList.add("block");
  container.appendChild(blocks);
}

function generate() {
  anime({
    targets: ".block",
    translateX: function () {
      return anime.random(-700, 700);
    },
    translateY: function () {
      return anime.random(-700, 700);
    },
    scale: function () {
      return anime.random(1, 5);
    },
  });
}

const btn = document.querySelector(".btnAni");
btn.addEventListener("click", generate);
728x90
LIST

'HTML _CSS' 카테고리의 다른 글

Unfold CSS Effect  (0) 2022.10.27
SOLAR Eclipse  (0) 2022.10.26
Light 3D Cube  (0) 2022.10.24
Candle Animation  (0) 2022.10.22
Box Card Hover Effects  (0) 2022.10.21