Carregando...

Button html css efeito partículas

Postado: 4 de janeiro de 2023 Tempo de Leitura: 2 Minutos

Button html css efeito partículas

Neste tutorial veremos como criar um button com html e css com efeito de partículas ao clicarmos nele.

Nesta seção, projetaremos uma estrutura básica no html. 

Usaremos A Tag <button> e a tag <i> para inserirmos um icone no botão.

Essas são as tags que usaremos no html

Vamos Adicionar o Html

<button class="btn-particulas"><i class="icon icon-thumbs-o-up"></i> Saiba mais</button>

Vamos Adicionar o CSS

Nesta seção, usaremos algumas propriedades CSS para estilizar o button.

.btn-particulas {

  display: inline-block;
  font-size: 1.2em;
  font-family: 'open_sansregular';
  padding: 0.6em 1em;
  -webkit-appearance: none;
  appearance: none;
  background-color: #00beea;
  color: #ffffff;
  border-radius: 50px;
  border: none;
  cursor: pointer;
  position: relative;
  transition: transform ease-in 0.1s, box-shadow ease-in 0.25s;
  box-shadow: 0 2px 25px rgba(140, 140, 140, 0.51);

}

.btn-particulas:focus {

  outline: 0;

}

.btn-particulas:before, .btn-particulas:after {
  
  position: absolute;
  content: "";
  display: block;
  width: 160%;
  height: 100%;
  left: -20%;
  z-index: 1000;
  transition: all ease-in-out 0.8s;
  background-repeat: no-repeat;

}

.btn-particulas:before {

  display: none;
  top: -80%;
  background-image: radial-gradient(circle, #00beea 20%, transparent 20%), radial-gradient(circle, transparent 20%, #00beea 20%, transparent 30%), radial-gradient(circle, #00beea 20%, transparent 20%), radial-gradient(circle, #00beea 20%, transparent 20%), radial-gradient(circle, transparent 10%, #00beea 15%, transparent 20%), radial-gradient(circle, #00beea 20%, transparent 20%), radial-gradient(circle, #00beea 20%, transparent 20%), radial-gradient(circle, #00beea 20%, transparent 20%), radial-gradient(circle, #00beea 20%, transparent 20%);
  background-size: 10% 10%, 20% 20%, 15% 15%, 20% 20%, 18% 18%, 10% 10%, 15% 15%, 10% 10%, 18% 18%;

}

.btn-particulas:after {

  display: none;
  bottom: -80%;
  background-image: radial-gradient(circle, #00beea 20%, transparent 20%), radial-gradient(circle, #00beea 20%, transparent 20%), radial-gradient(circle, transparent 10%, #00beea 15%, transparent 20%), radial-gradient(circle, #00beea 20%, transparent 20%), radial-gradient(circle, #00beea 20%, transparent 20%), radial-gradient(circle, #00beea 20%, transparent 20%), radial-gradient(circle, #00beea 20%, transparent 20%);
  background-size: 15% 15%, 20% 20%, 18% 18%, 20% 20%, 15% 15%, 10% 10%, 20% 20%;

}

.btn-particulas:active {
  
  transform: scale(1.1);
  background-color: #4c4c4c;

}

.btn-particulas.explodir:before {

  display: block;
  animation: topBolhas ease-in-out 0.75s forwards;

}

.btn-particulas.explodir:after {
  
  display: block;
  animation: bottomBolhas ease-in-out 0.75s forwards;

}

@keyframes topBolhas {
  0% {
    background-position: 5% 90%, 10% 90%, 10% 90%, 15% 90%, 25% 90%, 25% 90%, 40% 90%, 55% 90%, 70% 90%;
  }
  50% {
    background-position: 0% 80%, 0% 20%, 10% 40%, 20% 0%, 30% 30%, 22% 50%, 50% 50%, 65% 20%, 90% 30%;
  }
  100% {
    background-position: 0% 70%, 0% 10%, 10% 30%, 20% -10%, 30% 20%, 22% 40%, 50% 40%, 65% 10%, 90% 20%;
    background-size: 0% 0%, 0% 0%, 0% 0%, 0% 0%, 0% 0%, 0% 0%;
  }
}
@keyframes bottomBolhas {
  0% {
    background-position: 10% -10%, 30% 10%, 55% -10%, 70% -10%, 85% -10%, 70% -10%, 70% 0%;
  }
  50% {
    background-position: 0% 80%, 20% 80%, 45% 60%, 60% 100%, 75% 70%, 95% 60%, 105% 0%;
  }
  100% {
    background-position: 0% 90%, 20% 90%, 45% 70%, 60% 110%, 75% 80%, 95% 70%, 110% 10%;
    background-size: 0% 0%, 0% 0%, 0% 0%, 0% 0%, 0% 0%, 0% 0%;
  }
}

Vamos adicionar o Script para fazer o efeito de partículas

<script>
    
var animateButton = function(e) {

  e.preventDefault;
  //reset animation
  e.target.classList.remove('explodir');
  
  e.target.classList.add('explodir');
  setTimeout(function(){
    e.target.classList.remove('explodir');
  },800);
};

var bolhasButton = document.getElementsByClassName("btn-particulas");

for (var i = 0; i < bolhasButton.length; i++) {
  bolhasButton[i].addEventListener('click', animateButton, false);
}

</script>

Combinando as Três seções acima Html, Css e jQuery temos o seguinte Resultado!

Veja o Resultado baixo!

Baixar Código Veja Funcionando

Publicado por: Loop Nerd

644 Visualizações

2 respostas para “Button html css efeito partículas”

  1. loopnerd disse:

    Olá Mikael!
    Obrigado pela visita no BLOG.
    publicamos artigos todos os dias.
    seja bem-vindo.

  2. Mikael de Castro Meneses Barroso disse:

    Excelente desenvolvedor vocês .Salvam a minha vida sempre!

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

Artigos Relacionados