Mardi 17 janvier 2012 2 17 /01 /Jan /2012 20:02

Fichier requis : Jquery.latest.js

Utilisation : $("textarea").ajusttextarea(hauteur_minimale_du_textarea, hauteur_des_lignes);

 

jQuery.fn.ajusttextarea = function(minheight, lineheight) {
        return this.each(function() {
            object = $(this);
            $(this).css("overflow","hidden");
            $(this).css("resize","none");
            $(this).attr("wrap","hard");
            $(this).animate({height: minheight }, 200);
           
            $(this).keyup(function(e) {
                if ($(this).prop("scrollHeight") > minheight) {
                    if (e.keyCode == 8 || e.keyCode == 46) {
                        $(this).height($(this).prop("scrollHeight") - lineheight);
                        $(this).height($(this).prop("scrollHeight"));
                    } else if (e.ctrlKey || e.keyCode == 13)
                        if ($(this).prop("scrollHeight") > $(this).height())
                            $(this).animate({height: $(this).prop("scrollHeight") }, 200);
                }
            });
        });
    };

 

Pour tous question merci de commenter le poste.

Par agd243 - Publié dans : Programmation - Communauté : Progghub
Ecrire un commentaire - Voir les 0 commentaires
Retour à l'accueil
 
Créer un blog gratuit sur over-blog.com - Contact - C.G.U. - Rémunération en droits d'auteur - Signaler un abus - Articles les plus commentés