html移动端输入框,移动端页面 输入框怎么实现这种效果??

本文介绍了一段前端代码,展示了如何实现一个固定底部的容器,其高度根据textarea输入内容动态调整。通过监听textarea的输入变化,确保容器高度不超过限制,并实时更新。核心在于使用JavaScript控制元素高度和父容器高度的变化。
摘要由CSDN通过智能技术生成

刚入前端时候写的,我把代码复制改了下,没样式,你自己加上去。

xxx

*{

margin: 0;

padding: 0;

}

.container{

position: fixed;

left: 0;

bottom: 0;

width: 100%;

height: 64px;

max-height: 300px;

border-top: 1px solid #ddd;

}

.icon1{

width: 64px;

height: 64px;

line-height: 60px;

position: absolute;

left: 0;

bottom: 0;

text-align: center;

}

.icon2{

width: 64px;

height: 64px;

line-height: 60px;

position: absolute;

right: 0;

bottom: 0;

text-align: center;

}

.wrapper{

height: 100%;

padding: 2px 64px;

position: relative;

}

.textarea{

width: 100%;

height: 30px;

line-height: 30px;

max-height: 300px;

font-size: 18px;

resize: none;

border: 1px solid #ddd;

margin-top: 18px;

}

Icon1
Icon2

var areaHeight = $('#textarea').height()

$('#textarea').on('input propertychange',function(){

if(areaHeight > 200) {

return

}

var nowHeight = $(this).attr("scrollHeight")

if(nowHeight !== areaHeight){

$(this).css('height', nowHeight)

$('.container').css('height', $('.container').height() + nowHeight - areaHeight)

areaHeight = nowHeight

}

})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值