textarea滚动字体.html

本文介绍了一种使用HTML和JavaScript实现文本自动滚动的方法。通过创建动态div元素并将其添加到textarea中,使得文本能够定时更新,从而达到模拟滚动显示的效果。此方法适用于简单的动态文本展示场景。
textarea滚动字体.html


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>

<body>
<textarea id="textarea1" style="width:80;height:50"></textarea>
<script language=javascript>
var objTextarea=null
var temp=new Array();
var i=0;
function show()
{
if(i==temp.length){
i
=0;
}

objTextarea.appendChild(temp[i])
i
++
setTimeout(
"show()",1000)
}

function init(){
objTextarea
=document.getElementById("textarea1")
for(var i=0;i<10;i++)
{
var u=document.createElement("div")
u.innerHTML
=i.toString()+i.toString()+i.toString()+i.toString();
temp.push(u)
objTextarea.appendChild(u)

}

show()
}

</script>

<body onload=init()>

</body>
</html>
 
<el-input v-adaptive-textarea style="height: revert !important;" v-model="scope.row.nonStandardDescription" autosize :maxlength="1300" :placeholder="scope.row.nonPlaceholder" type="textarea" :disabled="isDone" @input="val => filterInput(scope.row, val)" ></el-input> directives: { // 指令名: 指令对象 'adaptive-textarea': { // 元素插入父节点时触发(首次渲染) inserted(el) { const textarea = el.querySelector('.el-textarea__inner'); if (!textarea) return; const resize = () => { textarea.style.height = 'auto'; // 重置高度 const computedStyle = window.getComputedStyle(textarea); const padding = parseFloat(computedStyle.paddingTop) + parseFloat(computedStyle.paddingBottom); // 创建临时 div 来精确测量文本所需高度 const tempDiv = document.createElement('div'); tempDiv.style.position = 'absolute'; tempDiv.style.visibility = 'hidden'; tempDiv.style.font = computedStyle.font; tempDiv.style.width = textarea.clientWidth + 'px'; tempDiv.style.whiteSpace = 'pre-wrap'; tempDiv.style.wordWrap = 'break-word'; tempDiv.style.padding = computedStyle.padding; tempDiv.innerText = textarea.value || ''; document.body.appendChild(tempDiv); let height = tempDiv.offsetHeight; const lineHeight = parseFloat(computedStyle.lineHeight) || 20; const minHeight = lineHeight * 2; height = Math.max(minHeight, height); textarea.style.height = height + 'px'; document.body.removeChild(tempDiv); }; // 初始执行一次 resize(); // 监听 input 事件 textarea.addEventListener('input', resize); // 保存函数以便后续使用或解绑 el.__resizeFn__ = resize; }, // 组件更新后调用(例如 v-model 数据变化) componentUpdated(el) { if (el.__resizeFn__) { el.__resizeFn__(); } }, // 解绑时移除事件监听(防内存泄漏) unbind(el) { const textarea = el.querySelector('.el-textarea__inner'); if (textarea && el.__resizeFn__) { textarea.removeEventListener('input', el.__resizeFn__); } delete el.__resizeFn__; } } }, vue2 当前代码中有两个明显问题; 1:初始没有值的时候, textarea的高度是正常的, 但是只要输入一个字, 高度就会变高大概6px,导致文字内容不居中了; 2: 编辑回显的时候, 多行文字的时候, 高度会差一点点, 导致出了滚动
最新发布
11-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

rjzou2006

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值