当前位置:网站首页>页面整屏滚动效果
页面整屏滚动效果
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>
边栏推荐
- Optimization of five data submission methods
- 攻防演练丨赛宁红方管控平台走进广东三地 助力数字政府网络安全建设
- Spark学习:为Spark Sql添加自定义优化规则
- PyQt5快速开发与实战 10.1 获取城市天气预报
- matlab as(assert dominance)
- 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%
- ASM外部冗余是否可以替换磁盘
- PyQt5 rapid development and actual combat 9.7 Automated testing of UI layer
- 行业案例 | 全面防护 赛宁助力能源工控安全建设
- Centos7 install mysql5.7
猜你喜欢

报错IDEA Terminated with exit code 1

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

Invalid bound statement (not found)出现的原因和解决方法

ERROR 1819 (HY000) Your password does not satisfy the current policy requirements

CentOS7 安装MySQL 图文详细教程

Error IDEA Terminated with exit code 1

centos7安装mysql5.7

golang-gin-优雅重启

The use of C# control CheckBox

pytorch gpu版本安装最新
随机推荐
C# using NumericUpDown control
清除浮动的四种方式及其原理理解
SAP message TK 248 solved
集群中增加数据节点与退役数据节点
网络层重点协议——IP协议
The use of C# control CheckBox
CentOS7 installation MySQL graphic detailed tutorial
CentOS7 - yum install mysql
Google Chrome(谷歌浏览器)安装使用
C#使用NumericUpDown控件
alert(1) (haozi.me)靶场练习
365-day challenge LeetCode1000 questions - Day 044 Maximum element in the layer and level traversal
Invalid bound statement (not found)出现的原因和解决方法
关于MySQL主从复制的数据同步延迟问题
Edge Cloud Explained in Simple Depth | 4. Lifecycle Management
IDEA找不到Database解决方法
Centos7 install mysql5.7
Productivity Tools and Plugins
硬盘分区,拓展C盘,不重装系统,不重装D盘软件的全教程。
Architecture Camp | Module 8