当前位置:网站首页>页面整屏滚动效果
页面整屏滚动效果
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>
边栏推荐
- C#控件ListView用法
- Two methods of NameNode failure handling
- sqlalchemy determines whether a field of type array has at least one consistent data with an array
- 架构实战营|模块8
- golang中使用泛型
- ECCV 2022 | 机器人的交互感知与物体操作
- 基于高阶微分器的无模型滑模控制器及其在自动电压调节器中的应用
- PHP Serialization: eval
- Four ways to clear the float and its principle understanding
- 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%
猜你喜欢
ECCV2022: Recursion on Transformer without adding parameters and less computation!
PartImageNet物体部件分割(Semantic Part Segmentation)数据集介绍
C# control ToolStripProgressBar usage
报错IDEA Terminated with exit code 1
架构实战营|模块8
golang八股文整理(持续搬运)
NameNode (NN) 和SecondaryNameNode (2NN)工作机制
NPM 使用介绍
操作符详解
电脑重要文件很多,如何备份比较安全?
随机推荐
Introduction to using NPM
PartImageNet物体部件分割(Semantic Part Segmentation)数据集介绍
CentOS7 安装MySQL 图文详细教程
基于模糊预测与扩展卡尔曼滤波的野值剔除方法
FastAPI 封装一个通用的response
Grab the tail of gold, silver and silver, unlock the programmer interview "Artifact of Brushing Questions"
The cluster of safe mode
分布式锁有哪些,怎么实现(分布式锁的三种实现的对比)
电脑重要文件很多,如何备份比较安全?
PyQt5快速开发与实战 9.7 UI层的自动化测试
Selenium自动化测试之Selenium IDE
How IDEA runs web programs
ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)解决办法
Architecture Camp | Module 8
P5019 [NOIP2018 提高组] 铺设道路
PyQt5 rapid development and actual combat 10.1 Get city weather forecast
C#控件StatusStrip使用
PHP序列化:eval
CentOS7 - yum install mysql
Error: npm ERR code EPERM