Submit with animation - Hover Effect

Asked

Viewed 30 times

-1

I’m making a "delete account" button where there’s an animation of blood drops falling. But I would like to make the animation start only when someone hovers over the top (Hover).

Could someone help me?

Thank you!

HTML

<!DOCTYPE html>
<html lang="en">
<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>Document</title>
    <link rel="stylesheet" href="./teste.css">
</head>
<body>
    <button type="submit" id="delete" name="delete">Deletar conta</button>
    <div class="blood">
        <div><img src="https://i.ibb.co/0DtRqY9/gota-De-Sangue.png" alt="gota-De-Sangue" border="0"></div>
        <div><img src="https://i.ibb.co/0DtRqY9/gota-De-Sangue.png" alt="gota-De-Sangue" border="0"></div>
        <div><img src="https://i.ibb.co/0DtRqY9/gota-De-Sangue.png" alt="gota-De-Sangue" border="0"></div>
        <div><img src="https://i.ibb.co/0DtRqY9/gota-De-Sangue.png" alt="gota-De-Sangue" border="0"></div>
    </div>
</body>
</html>

CSS

#delete {
    width: 235px;
    height: 40px;
    background-color: #ba1900;
    font-size: 18px;
    font-weight: bold;
    border: none;
    color: #fff;
    transition: all 0.3s;
    cursor: pointer;
  }
  
  #delete:hover {
    background-color: #ff0000;
    transition: all 0.3s;
  }
  
  .blood{
    
    position: absolute;
    top: 80px;
    left: 0;
    width: 100%;
    height: 100%;
  }
  
  .blood div{
    position: absolute;
    display: block;
  }
  
  .blood div:nth-child(1){
    left: 0%;
    animation: animate 10s linear infinite;
    animation-delay: -0.5s;
  }
  .blood div:nth-child(2){
    left: 13%;
    animation: animate 10s linear infinite;
    animation-delay: -2.5s;
  }
  
  .blood div:nth-child(3){
    left: 5%;
    animation: animate 10s linear infinite;
    animation-delay: -4.5s;
  }
  
  .blood div:nth-child(4){
    left: 11%;
    animation: animate 10s linear infinite;
    animation-delay: -6.5s;
  }
  
  @keyframes animate{
    0%{
      top: -10%;
    }
    100%{
      top: 10%
    }
  }

1 answer

-1

#delete {
    width: 235px;
    height: 40px;
    background-color: #ba1900;
    font-size: 18px;
    font-weight: bold;
    border: none;
    color: #fff;
    transition: all 0.3s;
    cursor: pointer;
  }
  
  #delete:hover {
    background-color: #ff0000;
    transition: all 0.3s;
  }
#delete:hover + .blood div {
   display: block;
}
  
  .blood{
    
    position: absolute;
    top: 80px;
    left: 0;
    width: 100%;
    height: 100%;
  }
  
  .blood div{
    position: absolute;
    display: none;
  }
  
  .blood div:nth-child(1){
    left: 0%;
    animation: animate 10s linear infinite;
    animation-delay: -0.5s;
  }
  .blood div:nth-child(2){
    left: 13%;
    animation: animate 10s linear infinite;
    animation-delay: -2.5s;
  }
  
  .blood div:nth-child(3){
    left: 5%;
    animation: animate 10s linear infinite;
    animation-delay: -4.5s;
  }
  
  .blood div:nth-child(4){
    left: 11%;
    animation: animate 10s linear infinite;
    animation-delay: -6.5s;
  }
  
  @keyframes animate{
    0%{
      top: -10%;
    }
    100%{
      top: 10%
    }
  }
<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>Document</title>
    <link rel="stylesheet" href="./teste.css">
</head>
<body>
    <button type="submit" id="delete" name="delete">Deletar conta</button>
    <div class="blood">
        <div><img src="https://i.ibb.co/0DtRqY9/gota-De-Sangue.png" alt="gota-De-Sangue" border="0"></div>
        <div><img src="https://i.ibb.co/0DtRqY9/gota-De-Sangue.png" alt="gota-De-Sangue" border="0"></div>
        <div><img src="https://i.ibb.co/0DtRqY9/gota-De-Sangue.png" alt="gota-De-Sangue" border="0"></div>
        <div><img src="https://i.ibb.co/0DtRqY9/gota-De-Sangue.png" alt="gota-De-Sangue" border="0"></div>
    </div>
</body>

The animations themselves are correct.

Failed to inform in your css that the principle, the class .blood div will start as display: none, and as soon as she got the Hover, she became display: block.

.blood div{
  position: absolute;
  display: none;
}

#delete:hover + .blood div {
  display: block;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.