Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox CSS3 Transition Won't Work

http://jsfiddle.net/Calum/5dqwJ/

CSS:

 textarea {
        height: 20px;
        margin: 20px;
        width: 585px;
        resize: none;
        overflow: hidden;
        vertical-align: top;
        transition: height 3s;
        -webkit-transition: height 3s;
        -moz-transition: height 3s;
        -o-transition: height 3s;
    }

Javascript:

 $(document).ready(function () {

     $("textarea").focus(function (event) {
         if ($(this).val().length === 0) {
             $(this).height(100);
             $(this).css('resize', 'vertical');
             $(this).attr('placeholder', null);
         }
     });


     $("textarea").blur(function (event) {
         if ($(this).val().length === 0) {
             $(this).height(20);
             $(this).attr('placeholder', "Enter comment");
             $(this).css('resize', 'none');
         }
     });

 });

HTML:

<textarea placeholder='Enter comment'></textarea>

In Chrome, IE and Opera, when you focus on the textarea it expands and contracts with the CSS3 transition.

When I do the same with FireFox, it doesn't animate anything.

Any ideas why?

Thanks!

like image 996
Teaqu Avatar asked Feb 23 '26 17:02

Teaqu


2 Answers

see This page for transitions

https://developer.mozilla.org/en-US/docs/CSS/Tutorials/Using_CSS_transitions

and you can do it completely by css no need to use js

remove $(this).height(20); and $(this).height(100); From JS and ADD this To css

textarea:focus{
   height: 100px;    
}
like image 97
mohammad mohsenipur Avatar answered Feb 26 '26 08:02

mohammad mohsenipur


If you add the required attribute on your textarea, you could use the :invalid pseudo-class to target an empty textarea:

textarea {
    height: 100px;
    margin: 20px;
    width: 585px;
    resize: vertical;
    overflow: hidden;
    vertical-align: top;
    -webkit-transition: height .3s;
    -moz-transition: height .3s;
    -o-transition: height .3s;
    transition: height .3s;    
}

textarea:invalid{  /* single line*/
    height: 20px;
    resize: none;
}

textarea:focus{
    height: 100px;
    resize: vertical;
}

demo

(add box-shadow: none; if you don't want the red border around it)

like image 20
nice ass Avatar answered Feb 26 '26 09:02

nice ass