$('textarea').each(function(){
this.setAttribute('style', 'height:' + (this.scrollHeight) + 'px;overflow-y:hidden;');
}).on('input',function(){
this.style.height = 'auto';
this.style.height = (this.scrollHeight) + 'px';
})
返回顶部:
//返回顶部
$(window).scroll(function(){
var sc=$(window).scrollTop();
if(sc>300){
$(".gethome").fadeIn();
}else{
$(".gethome").fadeOut();
}
})
$(".gethome").click(function(){
var sc=$(window).scrollTop();
$('body,html').animate({scrollTop:0},300);
})

本文介绍了一种使网页中的文本区域高度自动调整的方法,并实现了一个返回顶部的功能。通过监听输入事件来动态调整文本区域的高度,确保其始终能够完美适配内容。此外,还实现了当页面滚动超过一定距离时显示返回顶部按钮的功能。
1691

被折叠的 条评论
为什么被折叠?



