孤独的对话
效果:

思路:
不想分析了,能用就行
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="shortcut icon" href="#" />
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
}
.container {
padding-top: 15px;
margin: 30px;
width: 300px;
height: 350px;
background-color:burlywood;
overflow-y: scroll;
scrollbar-width: none; /* firefox */
-ms-overflow-style: none; /* IE 10+ */
}
.container::-webkit-scrollbar {
display: none; /* Chrome Safari */
}
.leftbox {
width: 180px;
height: 30px;
padding-left: 8px;
line-height: 30px;
background-color: bisque;
border-radius: 22px;
list-style-type: none;
margin-bottom: 15px;
}
</style>
</head>
<body>
<ul class="container">
<li class="leftbox">我是一个小小鸟~~~</li>
</ul>
<script>
let container = document.getElementsByClassName("container")[0];
let boxarr = []
for( let i = 0 ;i < 12; i++ ) {
let box = document.createElement("li");
box.innerHTML = i+1+".我是一个小小鸟~~~";
box.classList.add("leftbox");
boxarr.push(box);
}
let step = 0
let a = setInterval( ()=> {
container.appendChild(boxarr[step]);
step++;
let { scrollHeight,offsetHeight } = container;
console.log("scrollHeight:"+scrollHeight);
console.log("offetHeight"+ offsetHeight);
if ( scrollHeight > offsetHeight ) {
container.scrollTop = scrollHeight-offsetHeight;
console.log("scrollTop:"+ container.scrollTop);
}
if ( step > 11) clearInterval(a);
},1000)
</script>
</body>
</html>

浙公网安备 33010602011771号