Input Animation: HTML CSS Java Script @rayen-code

Input Animation: HTML CSS Java Script









HTML Code

<!-- -------------------- HTML -------------------- -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Input Animation</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>

    <div class="wrapper">

        <div class="input-box">
            <input type="text" required>
            <label for="">First&nbsp;Name</label>
        </div>
        <div class="input-box">
            <input type="text" required>
            <label for="">Last&nbsp;Name</label>
        </div>
    </div>
    

    <script src="main.js"></script>
</body>
</html>

CSS Code

/*-------------------- CSS --------------------*/
/* style */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Trebuchet MS', sans-serif;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #0a3740;
}

.input-box {
    width: 350px;
    position: relative;
    margin: 20px;

}

.input-box input {
    width: 100%;
    padding: 15px;
    background-color: transparent;
    border: 1px solid skyblue;
    outline: none;
    border-radius: 8px;
    color: white;
    text-transform: capitalize;
    font-size: 1rem;

}

.input-box input:focus,
.input-box input:valid{
    border-color: white;
}

.input-box label{
    position: absolute;
    left: 0;
    margin: 15px;
    pointer-events: none;
    color: skyblue;
    background-color: transparent;
    text-transform: uppercase;
}

.input-box label span{
    position: relative;
    display: inline-flex;
    letter-spacing: 0.1rem;
    background-color: #0a3740;
    transition: 0.2s ease-in-out;
}

.input-box input:focus ~ label span,
.input-box input:valid ~ label span{
    color: white;
    letter-spacing: 0.2rem;
    transform: translateY(-25px);
}

Java Script Code

//-------------------- Java Script --------------------//
// java script 
let label = document.querySelectorAll("label")

label.forEach(label => {
  let a = label.innerText.split("");
  console.log(a);

  label.innerHTML = a.map((letter, position) =>
    `<span style="transition-delay:${position * 40}ms">${letter}</span>`
  ).join("")
})

0 Comments