Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
How to make floating text onclick like cookie clicker?

enter image description here

When clicking the "big cookie" in cookie clicker, there is a popup showing how many cookies you earned (+276.341 septillion in this image), which slowly moves upward and fades out.

I wanted to implement a similar feature in my game, I sucessfully made the moving up and fading out part with css animations, however, there will be more than one of these numbers showing up at once, so how do I clone elements? And how do I make these show up at the cursor position?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I don't know what technologies you are using so here is how to do it with vanilla HTML and JS. You say you already made the HTML & CSS, so turn your HTML into a template

<template id="floating-text-template">
  <!-- your existing code -->
</template>

Now in your javascript, clone the template on each click

function click(event) {
  const template = document.getElementByID('#floating-text-template').content.cloneNode(true);
  const element = template.querySelector('.floating-text') //replace class with yours
  element.style.left = `${event.clientX}px`
  element.style.top = `${event.clientY}px`
  document.appendChild(element);
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda