欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery實現(xiàn)textarea 高度自適應(yīng)

 更新時間:2015年03月11日 08:55:45   投稿:hebedich  
用jquery實現(xiàn)的textarea 高度自適應(yīng)代碼。這個動畫效果比較流暢。適合新手學(xué)習(xí)。非常簡單實用,這里推薦給小伙伴們。

之前給大家分享過用Javascript控制文本框textarea高度隨內(nèi)容自適應(yīng)增長收縮,今天花了點時間換了種實現(xiàn)方法,總結(jié)一下

復(fù)制代碼 代碼如下:

jQuery.fn.extend({
            autoHeight: function(){
                return this.each(function(){
                    var $this = jQuery(this);
                    if( !$this.attr('_initAdjustHeight') ){
                        $this.attr('_initAdjustHeight', $this.outerHeight());
                    }
                    _adjustH(this).on('input', function(){
                        _adjustH(this);
                    });
                });
                /**
                 * 重置高度
                 * @param {Object} elem
                 */
                function _adjustH(elem){
                    var $obj = jQuery(elem);
                    return $obj.css({height: $obj.attr('_initAdjustHeight'), 'overflow-y': 'hidden'})
                            .height( elem.scrollHeight );
                }
            }
        });
        // 使用
        $(function(){
            $('textarea').autoHeight();
        });

以上就是本文所述的全部內(nèi)容了,希望對大家學(xué)習(xí)jQuery能夠有所幫助。

相關(guān)文章

最新評論