虚拟列表用于前端列表性能优化,通过对数据的截取和展示区域的定位,达到只渲染展示区域+1数量的列表项,以下为代码
<!DOCTYPE html>
<html lang="en">
<head>
<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>virtual-list</title>
<style>
.context {
position: relative;
width: 500px;
max-height: 600px;
background-color: #cccccc;
overflow: auto;
}
.virtual-context {
position: absolute;
left: 0;
right: 0;
z-index: -1;
}
.real-context {
position: absolute;
left: 0;
right: 0;
transform: translate3d(0);
}
.real-item {
width: 100%;
height: 150px;
background-color: #f2f2f2;
text-align: center;
line-height: