当前位置:网站首页>页面整屏滚动效果
页面整屏滚动效果
2022-07-31 13:10:00 【一只金牛座的崽】
效果展示
屏幕整屏滚动
代码实现
<!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>Document</title>
</head>
<style>
html,
body {
margin: 0px;
padding: 0px;
text-align: center;
height: 100%;
}
ul {
position: fixed;
width: 100%;
top: 0px;
}
ul,
li {
line-height: 100vh;
margin: 0px;
padding: 0px;
list-style: none;
font-size: 20px;
height: 100vh;
color: white;
transition-duration: 1s;
}
li:nth-child(odd) {
background: rgb(235, 171, 234);
}
li:nth-child(even) {
background: rgb(150, 220, 244);
}
</style>
<body>
<ul>
<li>第一页</li>
<li>第二页</li>
<li>第三页</li>
<li>第四页</li>
<li>第五页</li>
<li>第六页</li>
</ul>
</body>
<script>
let ulDom = document.querySelector('ul')
let liList = document.querySelectorAll('li')
const viewHeight = document.body.clientHeight
let index = 0;
var lastTime = 0;
//监听鼠标滚动
document.addEventListener('mousewheel', function (e) {
//节流
var nowTime = Date.now();
if (nowTime - lastTime > 2000) {
// 更新时间戳
lastTime = nowTime;
if (e.wheelDelta < 0) {
scrollEvent1()
} else {
scrollEvent1('back')
}
} else {
console.log('阻止', );
}
})
// 兼容火狐浏览器的监听事件
document.addEventListener('DOMMouseScroll', function (e) {
//节流
var nowTime = Date.now();
if (nowTime - lastTime > 2000) {
// 更新时间戳
lastTime = nowTime;
//
if (e.detail > 0) {
scrollEvent1()
} else {
scrollEvent1('back')
}
} else {
console.log('阻止', );
}
})
function scrollEvent1(behavior='forward') {
if (behavior ==='forward') {
if (index === liList.length-1) {
return false;
}
index += 1
console.log("鼠标滚轮后滚,看下一页")
ulDom.style.top = -index * viewHeight + 'px'
} else {
if (index === 0) {
return false;
}
index -= 1
console.log("鼠标滚轮前滚,看上一页")
ulDom.style.top = -index * viewHeight + 'px'
}
}
console.log('mousewheel',navigator);
</script>
</html>
边栏推荐
猜你喜欢

Istio微服务治理网格的全方面可视化监控(微服务架构展示、资源监控、流量监控、链路监控)

ECCV2022: Recursion on Transformer without adding parameters and less computation!

Optimization of five data submission methods

pytorch gpu版本安装最新

PyQt5快速开发与实战 9.7 UI层的自动化测试

【CPU设计实战】简单流水线CPU设计

How to quickly split and merge cell data in Excel

系统集成项目管理工程师(软考中级)知识点总结【挣值分析】【关键路径】

ECCV2022:在Transformer上进行递归,不增参数,计算量还少!

浏览器被hao360劫持解决办法
随机推荐
Anaconda安装labelImg图像标注软件
P5019 [NOIP2018 提高组] 铺设道路
计算机复试面试问题(计算机面试常见问题)
生产力工具和插件
ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
alert(1) (haozi.me)靶场练习
Four ways to clear the float and its principle understanding
JSP中如何借助response对象实现页面跳转呢?
深入浅出边缘云 | 4. 生命周期管理
查看Mysql数据库版本
Six Stones Programming: No matter which function you think is useless, people who can use it will not be able to leave, so at least 99%
行业案例 | 全面防护 赛宁助力能源工控安全建设
Spark学习:为Spark Sql添加自定义优化规则
PyQt5 rapid development and actual combat 10.1 Get city weather forecast
How to quickly split and merge cell data in Excel
PyQt5快速开发与实战10.2 复利计算 && 10.3 刷新博客点击量
Detailed explanation of network protocols and related technologies
Centos7 install mysql5.7
知名无人驾驶公司:文远知行内推
电脑重要文件很多,如何备份比较安全?