Home > Web Front-end > JS Tutorial > jquery implements textarea highly adaptive_jquery

jquery implements textarea highly adaptive_jquery

WBOY
Release: 2016-05-16 16:10:17
Original
1220 people have browsed it

I shared with you before that I used Javascript to control the textarea height to adaptively grow and shrink with the content. I spent some time today to change the implementation method and summarize it

Copy code The code is as follows:

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);
                     });
                });
                     /**
*Reset altitude
                        * @param {Object} elem
                                 */
function _adjustH(elem){
                      var $obj = jQuery(elem);
                         return $obj.css({height: $obj.attr('_initAdjustHeight'), 'overflow-y': 'hidden'})
.height(elem.scrollHeight);
                }
            }
        });
​​​​ //Use
         $(function(){
               $('textarea').autoHeight();
        });

The above is all the content described in this article. I hope it will be helpful to everyone learning jQuery.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template