当前位置:网站首页>div设置滚动和监听滚动距离
div设置滚动和监听滚动距离
2022-06-21 23:50:00 【kilito_01】
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.box{
width: 100vw;
height: 100vw;
/* 让div能被滚动事件监听到 需要让这个div设置overflow-y */
/* 需要让内容超出div设定的固定的宽高 */
/* 之前认为让内容超出div 页面也有滚动的效果,实际上撑开的是body而不是div
所以给window监听滚动事件是可以监听到的 给div监听不到是因为div并没有滚动
滚动的是body
*/
overflow-y: auto;
}
</style>
</head>
<body>
<!-- 闭包应用 -->
<div class="box">
<ul>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>222</li>
</ul>
</div>
<script>
document.querySelector('.box').addEventListener('scroll',(e)=>{
// console.log('scroll',e);
var ele = document.querySelector('.box')
// 这个就是滚动的距离
var top = ele.scrollTop
})
</script>
</body>
</html>
边栏推荐
猜你喜欢

如何使用物联网低代码平台进行报表管理?
![Chapter VIII exercises (45A) [microcomputer principles] [exercises]](/img/79/8311a409113331e72f650a83351b46.png)
Chapter VIII exercises (45A) [microcomputer principles] [exercises]

Im instant messaging source code + software +app with detailed package video building tutorial

珂朵莉树 范围查询 chtholly tree Old driver tree

pytorch学习01:梯度下降实现简单线性回归

The tangled truth about NFT and copyright

Query of the range of the cotolly tree chtolly tree old driver tree

The importance of rational selection of seal clearance of hydraulic slip ring

RISCV 的 cache

Opérations de bits bits et
随机推荐
leetcode 279. Perfect Squares 完全平方数(中等)
pytorch学习13:实现LetNet和学习nn.Module相关基本操作
Getting started with go web programming: validators
Qt之自制MP3播放器
Im instant messaging source code + software +app with detailed package video building tutorial
Bit operation bit or
记录一次小jsp的bug
如何判断一个男人将来是穷还是富?
花了2小时,搭建了一个物联网项目,值了 ~
Bit operation bit and
Acwing game 56
JVM调优简要思想及简单案例-老年代空间分配担保机制
In the operation exchange of the points system, which behaviors of users can obtain points
Why is the sample variance divided by (n-1)
View local IP address in vscode
American tourist visa interview instructions, let me focus!
珂朵莉树 范围查询 chtholly tree Old driver tree
DOM node
Arm assembles DCB, DCW, DCD and DCQ parsing
Web应用系统开发的两种流行架构