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

163
Visualizações
How to style in this hidden/show function?
// A function that hides or shows a selected element
function hideOrShow1() {
    
    // Select the element with id "theDIV"
    var x = document.getElementById("popup_roadmap_info_picture_1");
    
    // If selected element is hidden
    if (x.style.display === "block") {
    
      // Show the hidden element
      x.style.display = "none";
      
      // Else if the selected element is shown
    } else {
    
      // Hide the element
      x.style.display = "block";
      x.style.transition = "3s";
    }
  } 

I want the element which will be display to have a transition. Is it possible with js. NOTE: x.style.transition is not working.

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

0

You can't perform transitions if the element is toggled to display: none. You could use the opacity property or the height and width properties

about 4 years ago · Juan Pablo Isaza Relatório

0

Which property are you trying to transition? You can't transition display states from none to block, hence why it might seem that style.transition is not working.

You could transition the opacity, transform scale, width or height for an appearing/disappearing effect.

about 4 years ago · Juan Pablo Isaza Relatório

0

display: none to display:block doesn't have any steps in-between it's like a light switch off/on. You'll need to use a property that has a number value like opacity. When you use the .style attribute, you are overwriting everything within it. So if you do this:

// 👎
x.style.opacity = "1";
x.style.transition = "3s";

If you look in devtools and look at the HTML layout you should see:

<div class='popup' style='opacity:1'></div> <!--👎-->

Then this:

<div class='popup' style='transition:3s'></div> <!--👎-->

You need this:

<div class='popup' style='transition:3s;opacity:1'></div> <!--👍-->

In order to do the whole rulest with all of the properties and values at once you use .cssText property like this:

x.style.cssText = "transition: 3s; opacity:1;";  // 👍

function popup() {
  let x = document.querySelector(".popup");
  if (x.style.opacity === "0") {
    x.style.cssText = "transition: all 3s; font-size: 100px; opacity: 1;";
  } else {
    x.style.cssText = "transition: all 3s; font-size: 0; opacity: 0;";
  }
}

document.querySelector('button').onclick = popup;
<button>BOO</button>
<div class='popup' style='opacity: 0; font-size:0;'>👻</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