Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!