0

I use css to have animation (using transition) in a div. The content of the div is dynamical (can be 1 line or multiple lines).

I have 2 classes I switch to get the animation effect:

.class1{
    max-height: 200px;
}
.class2{
    max-height: 0;
}

My problem occurs when the I have only 1 line in the div, so there's "delay" until the 1 line disappears (because the height changes from 200px to 0 while the actual size is only 30px).

I tried to use element.style.maxHeight = elem.offsetHeight + "px" to set the max-height size but it didn't work so I want to change max-height in the class (class1 or class2) to fit the actual size.

How can I change the content of a class (I don't want to have: "style = max-height: 100px" in my div)?

Dror
  • 177
  • 3
  • 11
  • 1
    why not create another class with that `max-height` and apply that class instead? (like: `.class3 {max-height: 100px;}`), this is not editing a class, it is applying it. – jackJoe Jan 11 '16 at 10:19
  • You just might want to try to do [this](http://stackoverflow.com/a/8331169/3880255). – Clemens Himmer Jan 11 '16 at 10:38
  • Use jQuery to either remove class or change style using `.css` method ,, there are various solutions to your problem – Amar Singh Jan 11 '16 at 11:10
  • @jackJoe the text can be in multiple lines so I'll need multiple classes, each one for different number of lines... not good idea... – Dror Jan 11 '16 at 12:14
  • @Tarekis I saw that thread and it has the same problem: when I delete some of the
  • element and move the cursor from the div, I'll see the delay too...
  • – Dror Jan 11 '16 at 12:16
  • Is [this](https://jsfiddle.net/Tarekis/khhvu2qc/) what you need? It's just some basic thing with only the element itself being clickable, but if it is i'll write an answer. – Clemens Himmer Jan 11 '16 at 12:57
  • @Tarekis no, it's not what I meant... How can I change dynamically to have: .class1{max-height: 100px} – Dror Jan 11 '16 at 13:52
  • Guess you need [this](http://stackoverflow.com/a/2076345/3880255) then? – Clemens Himmer Jan 11 '16 at 13:57