当前位置:网站首页>移动端整页滑屏示例(上下滑动整屏)(整理)
移动端整页滑屏示例(上下滑动整屏)(整理)
2022-06-10 11:55:00 【000000001111】
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0" />
<meta name="format-detection" content="telephone=no" />
<meta content="yes" name="mobile-web-app-capable">
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<title>移动端整页滑屏示例</title>
<style type="text/css">
*{
padding:0;margin:0}
body,html{
height:100%;background-color:#000}
.wrap{
width:100%;height:100%;overflow:hidden}
.wrap2{
width:100%;height:1000%;transition:.3s linear}
.page{
width:100%;height:10%;background-color:#fdfdfd;font-size:100px;line-height:400px;text-align:center;font-weight:700}
</style>
</head>
<body>
<div class="wrap" id="wrap">
<div class="wrap2" id="wrap2">
<div class="page">我是第一屏内容</div>
<div class="page" style="background-color:#ccc;">我是第二屏内容</div>
<div class="page">我是第三屏内容</div>
<div class="page" style="background-color:#ccc;">我是第四屏内容</div>
<div class="page">我是第五屏内容</div>
<div class="page" style="background-color:#ccc;">我是第六屏内容</div>
</div>
</div>
<script type="text/javascript">
//重要!禁止移动端滑动的默认事件
document.body.addEventListener('touchmove', function(event) {
event = event ? event : window.event;
if(event.preventDefault) {
event.preventDefault()
} else {
event.returnValue = false
}
}, false)
var pages = function(obj) {
var box = document.getElementById(obj.wrap);
var box2 = document.getElementById(obj.wrap2);
var len = obj.len;
var n = obj.n;
var startY, moveY, cliH;
//获取屏幕高度
var getH = function() {
cliH = document.body.clientHeight
};
getH();
window.addEventListener('resize', getH, false);
//touchStart
var touchstart = function(event) {
if(!event.touches.length) {
return;
}
startY = event.touches[0].pageY;
moveY = 0;
};
//touchMove
var touchmove = function(event) {
if(!event.touches.length) {
return;
}
moveY = event.touches[0].pageY - startY;
box2.style.transform = 'translateY(' + (-n * cliH + moveY) + 'px)'; //根据手指的位置移动页面
};
//touchEnd
var touchend = function(event) {
//位移小于+-50的不翻页
if(moveY < -50) n++;
if(moveY > 50) n--;
//最后&最前页控制
if(n < 0) n = 0;
if(n > len - 1) n = len - 1;
//重定位
box2.style.transform = 'translateY(' + (-n * 10) + '%)'; //根据百分比位置移动页面
console.log(n)
};
//touch事件绑定
box.addEventListener("touchstart", function(event) {
touchstart(event)
}, false);
box.addEventListener("touchmove", function(event) {
touchmove(event)
}, false);
box.addEventListener("touchend", function(event) {
touchend(event)
}, false);
};
pages({
wrap: 'wrap', //.wrap的id
wrap2: 'wrap2', //.wrap2的id
len: 6, //一共有几页
n: 0 //页面一打开默认在第几页?第一页就是0,第二页就是1
});
</script>
</body>
</html>
边栏推荐
猜你喜欢

浅谈分布式事务

How zoom closes the microphone when joining a meeting

web端开发,web开发选型

Transfomer components and pytoch

2022 CISCN初赛 Satool

Cvpr22 oral | Hong Kong Chinese proposed transrank: sequencing loss + self supervision =sota

La poignée d'enseignement de la station B vous apprend à utiliser le masque yolov5 pour tester les éléments de l'enregistrement le plus complet (apprentissage profond / détection d'objets / pythorch)

Fun face recognition software

Transfomer各组件与Pytorch

海量数据:华为高斯数据库第一股(深度)
随机推荐
现场勘察制度
Transfomer自实现与官方库
How zoom closes the microphone when joining a meeting
多线程杀手锏---countDownLatch&&CyclicBarrier
怎样将PDF作为矢量图插入PPT中
使用Joern处理大量文件,生成PDG速度很慢的解决方法
远程访问Tensorboard
如何配置多数据源
绿盟数据库防火墙(DAS-FW)获得鲲鹏Validated认证
B站教学 手把手教你使用YOLOV5之口罩检测项目 最全记录详解 ( 深度学习 / 目标检测 / pytorch )
期末考试——编译原理
C语言最佳实践之库文件介绍(下)
西骏数据与阿里云携手合作,获得阿里云产品集成认证!
SQL Server AlwaysOn viewing data synchronization progress
Remote access to tensorboard
Do you have an online stock account? Is it safe to open an account online?
Transfomer components and pytoch
Flutter库推荐Sizer 可帮助您轻松创建响应式 UI
How data is stored in memory
Using Joern to process a large number of files and generate PDG is a slow solution