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
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.
Statement: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