当前位置:网站首页>页面整屏滚动效果
页面整屏滚动效果
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>
边栏推荐
猜你喜欢
Introduction to the PartImageNet Semantic Part Segmentation dataset
The use of C# control CheckBox
PyQt5快速开发与实战 9.7 UI层的自动化测试
C#控件 ToolStripProgressBar 用法
报错IDEA Terminated with exit code 1
NPM 使用介绍
C# using NumericUpDown control
图像大面积缺失,也能逼真修复,新模型CM-GAN兼顾全局结构和纹理细节
尚硅谷–MySQL–基础篇(P1~P95)
ICML2022 | 面向自监督图表示学习的全粒度自语义传播
随机推荐
SAP 电商云 Spartacus UI 和 Accelerator UI 里的 ASM 模块
全局平均池化层替代全连接层(最大池化和平均池化的区别)
聊聊 SAP 产品 UI 上的消息显示机制
Grab the tail of gold, silver and silver, unlock the programmer interview "Artifact of Brushing Questions"
ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
IDEA连接MySQL数据库并执行SQL查询操作
NameNode (NN) 和SecondaryNameNode (2NN)工作机制
The use of C# control CheckBox
C# control ToolStripProgressBar usage
Flutter keyboard visibility
centos7安装mysql5.7步骤(图解版)
PyQt5快速开发与实战 10.1 获取城市天气预报
go中select语句
行业案例 | 全面防护 赛宁助力能源工控安全建设
Productivity Tools and Plugins
ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)解决办法
MATLAB | 我也做了一套绘图配色可视化模板
电脑重要文件很多,如何备份比较安全?
深入浅出边缘云 | 4. 生命周期管理
LRU缓存[线性表 -> 链表 -> hash定位 -> 双向链表]