当前位置:网站首页>Long list optimized virtual scrolling
Long list optimized virtual scrolling
2022-07-05 14:36:00 【Forgive me for not being free and easy enough】
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
ul.container {
position: relative;
width: 500px;
max-height: 500px;
/* Limit the size of the container display area */
margin: 0;
padding: 0;
border: 1px solid #000;
overflow-y: auto;
list-style-type: none;
}
ul.container li {
position: absolute;
width: 100%;
height: 50px;
color: white;
text-align: center;
line-height: 50px;
}
</style>
</head>
<body>
<ul class="container"></ul>
<script>
const dataList = Array.from({
length: 1000 }).map((item, index) => index); // Generate 1000 pieces of data
const $list = document.querySelector(".container")
const size = 20 // Visual area 10 strip , But you need to scroll Take the number of pieces each time 20
createItem(0) // The default from the 0 Start (i)
$list.setAttribute("style", `height: ${
50 * dataList.length}px;`); // Set container height
function handleScroll(e) {
// Calculations should show those
const i = Math.floor(e.target.scrollTop / 50);
createItem(i);
}
function createItem(i) {
$list.innerHTML = dataList.slice(i, i + size).map(
item =>
`<li style="top: ${
item * 50}px; background: ${
createHexColor()};">${
item}</li>`)
.join("");
}
$list.onscroll = throttle(handleScroll, 20);
function throttle(fn, delay) {
// Events triggered by scrolling
let lastTime = 0;
return function () {
const nowTime = +new Date();
if (nowTime - lastTime > delay) {
fn.apply(this, arguments);
lastTime = nowTime;
}
}
}
function createHexColor() {
const colorStr = "6789abcdef",
len = colorStr.length;
let colorVal = "#";
for (let i = 0; i < 6; i++) {
colorVal += colorStr[Math.floor(Math.random() * len)];
}
return colorVal
}
</script>
</body>
</html>
边栏推荐
- 一网打尽异步神器CompletableFuture
- R language ggplot2 visualization: use ggplot2 to visualize the scatter diagram, and use the labs parameter to customize the X axis label text (customize X axis labels)
- Topology visual drawing engine
- 最长公共子序列 - 动态规划
- R language dplyr package select function, group_ By function, mutate function and cumsum function calculate the cumulative value of the specified numerical variable in the dataframe grouping data and
- World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
- Thymeleaf 使用后台自定义工具类处理文本
- Thymeleaf common functions
- 浅谈Dataset和Dataloader在加载数据时如何调用到__getitem__()函数
- R language ggplot2 visualization: gganimate package is based on Transition_ The time function creates dynamic scatter animation (GIF) and uses shadow_ Mark function adds static scatter diagram as anim
猜你喜欢
Pointer operation - C language
【NVMe2.0b 14-9】NVMe SR-IOV
【学习笔记】阶段测试1
729. 我的日程安排表 I :「模拟」&「线段树(动态开点)」&「分块 + 位运算(分桶)」
实现一个博客系统----使用模板引擎技术
分享 20 个稀奇古怪的 JS 表达式,看看你能答对多少
Chow Tai Fook fulfills the "centenary commitment" and sincerely serves to promote green environmental protection
分享 12 个最常用的正则表达式,能解决你大部分问题
freesurfer运行完recon-all怎么快速查看有没有报错?——核心命令tail重定向
如何将电脑复制的内容粘贴进MobaXterm?如何复制粘贴
随机推荐
选择排序和冒泡排序
C语言中限定符的作用
总量分析 核算方法和势方法 - 分摊分析
How to choose the appropriate certificate brand when applying for code signing certificate?
CPU设计实战-第四章实践任务三用前递技术解决相关引发的冲突
实现一个博客系统----使用模板引擎技术
There is a powerful and good-looking language bird editor, which is better than typora and developed by Alibaba
IPv6与IPv4的区别 网信办等三部推进IPv6规模部署
Intelligent supply chain collaboration system solution for daily chemical products industry: digital intelligent SCM supply chain, which is the "acceleration" of enterprise transformation
How to protect user privacy without password authentication?
Thymeleaf 常用函数
SaaS multi tenant solution for FMCG industry to build digital marketing competitiveness of the whole industry chain
729. 我的日程安排表 I :「模拟」&「线段树(动态开点)」&「分块 + 位运算(分桶)」
anaconda使用中科大源
LeetCode_ 69 (square root of x)
R language ggplot2 visual density map: Visual density map by group and custom configuration geom_ The alpha parameter in the density function sets the image transparency (to prevent multiple density c
安装配置Jenkins
[detailed explanation of Huawei machine test] character statistics and rearrangement
通过npm 或者 yarn安装依赖时 报错 出现乱码解决方式
周大福践行「百周年承诺」,真诚服务推动绿色环保