Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Prevent div to expand immediately

I’m trying to prevent the div size from expanding immediately.

I’ve tried using transition-duration but it’s not working.

You can try pressing the button to see the div expand immediately.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How do I make the speed not changing immediately?

var container = document.getElementById("test");

function up() {
  container.style.width="300px";
}

function down() {
  container.style.width="120px";
}
.ct {
  display: flex;
  flex-direction: row;
  transition-duration: 0.6s;
}

#test {
  width: 120px;
  height: 120px;
  background-color: grey;
}
<div class="ct">
  <button onclick="up()">up</button>
  <button onclick="down()">down</button>
</div>

<div id="test"></div>

>Solution :

you have to add transition to #test element. like below:

var container = document.getElementById("test");

function up() {
  container.style.width="300px";
}

function down() {
  container.style.width="120px";
}
.ct {
  display: flex;
  flex-direction: row;
}

#test {
  width: 120px;
  height: 120px;
  background-color: grey;
  transition-duration: 0.6s;
  transition: ease width 0.2s;
}
<div class="ct">
  <button onclick="up()">up</button>
  <button onclick="down()">down</button>
</div>

<div id="test"></div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading