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

242
Visualizações
How I can animate this diamond image so it looks as 3d diamond is rotating downward?

I want to animate this diamond diamong images in such a way it look like a real diamond is rotating. As a 3d diamond is rotating downward. Please help me it means a lot. Thanks.

what i try

animation is used in second section of website

<section class="relative flex items-center justify-center w-screen h-screen bg-gray-600">
    <div class="absolute w-40 h-20 top-28" >
        <div class="">
            <img  class="ml-3 w-36 diamond_animtion"  src="fake/diamond.png" alt="">
        </div>
        <img class="absolute ml-12 top-14" style="width: 70px;" src="fake/Prong.png" alt="">
    </div>
    <img class="w-96 h-96" src="fake/ring.png" alt="">
</section>

how i can slow down animation speed

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

0

You can do the trick using css overflow and background position, then use JS to make it move.

let height = 0,
  steps = 0;
const animation = setInterval((function() {
  height += 290.35, document.getElementById("diamond").style.backgroundPosition = `0px -${height}px`, 18 == steps++ && clearInterval(animation)
}), 42);

//With scroll
#diamond {
  height: 290px;
  width: 351px;
  background: url('https://i.stack.imgur.com/HplbX.png') 0px 0px;
  background-size: 100%;
  overflow: hidden;
}
<div id="diamond">
</div>

According to your example, here's could be a solution to animate diamond when scroll.

NOTE: This solution is not suitable for production because of scroll steps glitch but you can use it and modify to fit your needs

let bounding,
  height = 145, //Equal your diamond CSS height
  topPos = 0,
  scrollPos = 0,
  steps = 0,
  diamond = document.getElementById("diamond");

function scrollDiamond(o) {
  "down" === o && steps < 18 ? (act = `0px -${topPos+=height}px`, steps++) : "up" === o && steps > -1 && (act = `0px -${topPos-=height}px`, steps--)
  diamond.style.backgroundPosition = act;
}
window.addEventListener("scroll", (function() {
  bounding = document.body.getBoundingClientRect().top;
  bounding > scrollPos ? scrollDiamond("up") : scrollDiamond("down"), scrollPos = bounding
}));
body {
  height: 200vh;
}

#diamond {
  position: fixed;
  /* Your image heigh divided by 40 (or whatever you want) */
  height: 145px;
  width: 175px;
  /* Your image width divided by 40 (or whatever you want)*/
  background: url('https://i.stack.imgur.com/HplbX.png') 0px 0px/100%;
}
<div id="diamond"></div>

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