html5 touchmove 怎么可以一直滑动
2016-07-18 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
可以在手机上测试这段代码
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1 user-scalable=0"/>
<title>mySwipe</title>
<style>
.clearFixd:after{content:"."; height: 0; visibility: hidden; clear:both; display:"block"}
*{ margin:0; padding:0;}
#main{overflow: hidden; overflow: hidden; position: relative;}
.content{width:100%; height:400px; background: #f67d42;}
/* #main{background: #f45643;} */
</style>
</head>
<body>
<div id="canvas">
<div class="content clearFixd" >
</div>
</div>
<script>
var canvas = document.getElementById("canvas");
var div=canvas.children[0];
var startX,startY;
function touchStart(event){
var touch=event.touches[0];
startX=touch.pageX;
startY=touch.pageY;
}
function touchMove(event){
var touch=event.touches[0];
timer = setInterval(function() {
renderTouches(touches);
}, 1);
var x = touch.pageX - startX;
var y = touch.pageY - startY;
div.style.webkitTransform =canvas.style.msTransform =
div.style.MozTransform = 'translate(0, ' + y + 'px)';
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1 user-scalable=0"/>
<title>mySwipe</title>
<style>
.clearFixd:after{content:"."; height: 0; visibility: hidden; clear:both; display:"block"}
*{ margin:0; padding:0;}
#main{overflow: hidden; overflow: hidden; position: relative;}
.content{width:100%; height:400px; background: #f67d42;}
/* #main{background: #f45643;} */
</style>
</head>
<body>
<div id="canvas">
<div class="content clearFixd" >
</div>
</div>
<script>
var canvas = document.getElementById("canvas");
var div=canvas.children[0];
var startX,startY;
function touchStart(event){
var touch=event.touches[0];
startX=touch.pageX;
startY=touch.pageY;
}
function touchMove(event){
var touch=event.touches[0];
timer = setInterval(function() {
renderTouches(touches);
}, 1);
var x = touch.pageX - startX;
var y = touch.pageY - startY;
div.style.webkitTransform =canvas.style.msTransform =
div.style.MozTransform = 'translate(0, ' + y + 'px)';
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询