原理 setInterval定时器+substring()方法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<input class="demo1" type="text" value="阿萨德发过火就哭了!"> //input例子
<div class="demo2">去玩儿推欧赔破一有挺热情!</div> //div例子
</body>
<script>
let demo1 = document.querySelector('.demo1')
let demo2 = document.querySelector('.demo2')
let w1 = demo1.value.length //获取input内文字的长度
let w2 = demo2.innerHTML.length //获取div中文字内容长度
let timer = setInterval(function () {
let start1 = demo1.value.substring(0, 1) //截取第一个字 --- "阿"
let end1 = demo1.value.substring(1, w1) //截取除了第一个字后面所有内容 ---"萨德发过火就哭了!"
demo1.value = end1 + start1 //字符串拼接
let start2 = demo2.innerHTML.substring(0, 1)
let end2 = demo2.innerHTML.substring(1, w2)
demo2.innerHTML = end2 + start2
}, 500)
</script>
</html>