0

Is it possible to add a transition for all, but just disable a single one too? For example:

textarea {
  width: 400px;
  height: 60px;
  min-height: 60px;
  resize: vertical;
  color: #ccc;
  border: 1px solid #ccc;
  transition: all 0.3s, height 0s;
}

textarea:focus {
  color: #333;
  border: 3px solid #f00;
  padding: 10px;
}
<textarea>text</textarea>

You see (at least in firefox) that on resize of the box, that it lags. In Chrome and IE there is no problem with it, works fine.

Also using a time like 1ms for disabling is not working:

textarea {
  width: 400px;
  height: 60px;
  min-height: 60px;
  resize: vertical;
  transition: all 0.5s, height 1ms;
}
<textarea placeholder="test"></textarea>
eisbehr
  • 12,243
  • 7
  • 38
  • 63
  • so maybe a Firefox bug then ? – Temani Afif Mar 06 '18 at 08:48
  • What attributes are being transitioned? – Brett DeWoody Mar 06 '18 at 08:48
  • I don't understand your question? It's `all` except `height`?! I don't want to add every single attribute in this case. That would be a solution, I know. But I was hoping there is a way to do it like this. ;) @BrettDeWoody – eisbehr Mar 06 '18 at 08:58
  • Possible duplicate of [How do I apply CSS3 transition to all properties except background-position?](https://stackoverflow.com/questions/10604389/how-do-i-apply-css3-transition-to-all-properties-except-background-position) – Brett DeWoody Mar 06 '18 at 08:59
  • Change the transition duration of the property you don't want to transition to `1ms`. – Brett DeWoody Mar 06 '18 at 09:00
  • Already did this, it's not working too. Added this to the question too. So this is no duplicate. @BrettDeWoody – eisbehr Mar 06 '18 at 09:02
  • Back to the original question then, can you update the question to show the transitions you're applying so we can reproduce the exact issue. – Brett DeWoody Mar 06 '18 at 09:03
  • Just resize the box height in my example in firefox. You will see that the resize lags/hangs. Everything else is fine. @BrettDeWoody – eisbehr Mar 06 '18 at 09:07
  • But what are you transitioning that you need the transition in the first place? – Brett DeWoody Mar 06 '18 at 09:11
  • I use different transitions on this element, like text color, border color, size, ... I could write everything manually, but it would be nice if I could use `all` instead, to keep it small. I added some other transitions to the first example if it is helpful for you ... @BrettDeWoody – eisbehr Mar 06 '18 at 09:15

3 Answers3

0

Do you want to disable the transition only in firefox browser thought?

Have you tried to use -moz-document url-prefix ?

@-moz-document url-prefix() { 
  textarea{
     transition:none !important;
  }
}

or you can set:

  textarea{
  width: 400px;
  height: 60px;
  min-height: 60px;
  resize: vertical;
  color: #ccc;
  border: 1px solid #ccc;
  transition: all 0.3s, height 0s;
-moz-transition-property: none;
}
Lib3r74
  • 1
  • 4
0

The use of transition: none seems to be working.

  • For example i created one with transition and one without.

    textarea {
      width: 400px;
      height: 60px;
      min-height: 60px;
      resize: vertical;
      transition: all 0.5s, height 1ms;
    }
    
    textarea.notransition{
        -moz-transition: none;
        -webkit-transition: none;
        -o-transition: color 0 ease-in;
        transition: none;
    }
<textarea class="notransition">without transition</textarea> <textarea>with transition</textarea>

And you have the following CSS.
- I added a class to textarea if you want a textarea without transition / you also can create a new class for other stuff if you want.

I hope this example is usefull for you.

  • Thanks for your answer, but please read the question again. That is not what I want. – eisbehr Mar 06 '18 at 11:29
  • @eisbehr sry i dont get your question could you specify it please ? –  Mar 06 '18 at 12:27
  • I don't want all transition to be remove, only a single one for all entries. So a second class is not an option. See my first example. – eisbehr Mar 06 '18 at 13:40
0

Seems like a bug with Firefox, and I can't see any reliable CSS-only solution. So here's a JS solution.

We'll add an event listener on focus which removes the transition after a delay, then re-adds the transition on blur.

const fixFirefoxResizeTransition = el => {
  const elTransition = el.style.transition;
  const elTransitionDuration = parseFloat(getComputedStyle(el)['transitionDuration']) * 1000;
  
  el.addEventListener("focus", () => {
    setTimeout(() => {
      el.style.transition = "none"
    }, elTransitionDuration);
  });

  el.addEventListener("blur", () => {
    el.style.transition = elTransition;
  });
}

fixFirefoxResizeTransition(document.querySelector("textarea"));
textarea {
  width: 100%;
  height: 60px;
  min-height: 60px;
  resize: vertical;
  box-sizing: border-box;
  color: #ccc;
  border: 1px solid #ccc;
  transition: all 0.3s, height 1ms;
}

textarea:focus {
  color: #333;
  border: 3px solid #f00;
  padding: 10px;
}
<textarea>text</textarea>
Brett DeWoody
  • 59,771
  • 29
  • 135
  • 184
  • But this would not work when resize the box without focus. ;) I think you may be right, it's a bug and I have no solution too. Think I must split all transitions into single arguments. Thanks anyway ... – eisbehr Mar 06 '18 at 16:11
  • Hmm, yes true. It would be necessary to detect a click on the resize, vs a click on the textarea in that case. – Brett DeWoody Mar 06 '18 at 16:37
  • I've looked into a few options, but other than detecting clicks in the bottom-right corner of the element, there's no way to know the element is being resized vs focused. – Brett DeWoody Mar 07 '18 at 23:44