简单的css3全屏滚动

35 篇文章 0 订阅
7 篇文章 0 订阅

<!DOCTYPE html>
<html><head>
<title>qqqqqqqq</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
<meta content="telephone=no" name="format-detection" />
<link type="text/css" href="lib/normalize.css" rel="stylesheet"/>
<style>
body,#wrapper{min-height:100%;height:100%;overflow:hidden;}
#wrapper section{position:absolute;width:100%;height:100%;min-height:100%;}
section{top:100%;left:0;opacity:0;
}
section.active{top:0;z-index:2;opacity:1; /*transition:all 1s;*/}

section.pre{
-webkit-animation: pre 1s 1;
}
@-webkit-keyframes pre{
0%{top:0;opacity:1}
99%{top:-99%;opacity:1}
100%{top:-100%;opacity:0}
}

section.next{
-webkit-animation: next 1s 1;
}
@-webkit-keyframes next{
0%{top:100%;opacity:1;z-index:2;}
100%{top:0;opacity:1;z-index:2;}
}

.s1{background:#ccc;}
.s2{background:gold;}
.s3{background:pink;}
.s4{background:green;}
.swipeTip{position:absolute;width:3em;line-height:2em;bottom:0;left:0;right:0;margin:auto;z-index:10;text-align:center;
color:#fff;
background:#000;
border-radius:100%;
/**/-webkit-animation: st 1s infinite;
animation: st 1s infinite;
}
@-webkit-keyframes st{
0%{bottom:0;}
50%{bottom:0.8em;}
100%{bottom:0em;}
}
@keyframes st{
0%{bottom:0;}
50%{bottom:0.4em;}
100%{bottom:0em;}
}
</style>
</head>
<body onload="init()">
<div id="wrapper">
<section class="s1 active">
s1
</section>
<section class="s2">
s2
</section>
<section class="s3">
s3
</section>
<section class="s4">
s4
</section>

<div class="swipeTip" id="swipeTip">▲</div>
</div>
<script>
var pfx = ["webkit", "moz", "MS", "o", ""];
function PrefixedEvent(element, type, callback) {
for (var p = 0; p < pfx.length; p++) {
if (!pfx[p]) type = type.toLowerCase();
element.addEventListener(pfx[p]+type, callback, false);
}
}
function init(){

var sections = document.querySelectorAll("section");
var size = sections.length;
var index = 0;
var lock = false;
for(var i=0; i < size; i++){
PrefixedEvent(sections[i], "AnimationEnd", function(){
if(/next/.test(this.className)){
this.className = this.className.replace(/pre|next/g,"").replace(/\s*$/,"") + " active";
lock = false;
}else{
this.className = this.className.replace(/pre|next/g,"").replace(/\s*$/,"");
}

});
}
document.body.addEventListener("touchmove",function(e){
e.preventDefault();
},false);


var startX = 0;
var startY = 0;

var dx = 0;
var dy = 0;
document.getElementById("swipeTip").addEventListener("touchstart",function(e){
this.style.webkitAnimationPlayState = "paused";
startX = e.touches[0].pageX;
startY = e.touches[0].pageY;
});
document.getElementById("swipeTip").addEventListener("touchmove",function(e){
e.preventDefault();

dx = e.touches[0].pageX - startX;
dy = e.touches[0].pageY - startY;
});
document.getElementById("swipeTip").addEventListener("touchend",function(e){
this.style.webkitAnimationPlayState = "running";
if(lock){
return;
}
//垂直方向滚动的简单判断
if(Math.abs(dy) > Math.abs(dx)){

lock = true;

e.preventDefault();
sections[index].className = sections[index].className.replace(/\s*active\s*/g,"") + " pre";
index++;
index = index % size;
sections[index].className = sections[index].className + " next";
}

},false);
}

</script>
</body></html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值