这个手机上的数字滚动太快了,如何能慢下来,滑一下滚一个数字?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.babygroup-picker{
width: 420px
}
.babygroup-picker>input {
float: left;
width: 200px;
height: 50px;
font-size: 24px;
text-align: center;
border: 1px solid #dcdddd;
box-sizing: border-box;
-webkit-appearance: none;
border-radius: 0
}
.babygroup-pickoff {
float: right;
height: 50px;
}
.babygroup-pickoff ul{
float: left;
margin: 0;
padding: 0;
}
.babygroup-pickoff li {
float: left;
width: 50px;
height: 50px;
font-size: 24px;
color: #595757;
text-align: center;
line-height: 50px;
margin-left: 20px;
border: 1px solid #dcdddd;
background: linear-gradient(to bottom, #d7d8d8 0%, #f4f4f4 50%, #d7d8d8 100%);
box-sizing: border-box;
overflow: hidden
}
</style>
</head>
<body>
<div class="babygroup-picker">
<input id="inline" type="text">
<div class="babygroup-pickoff">
<ul>
<li>0</li>
<li>0</li>
<li>0</li>
</ul>
</div>
</div>
<script>
// 上下滑动
var num = 0;
$("body").on("touchstart", '.babygroup-pickoff li', function (e) {
e.preventDefault();
startX = e.originalEvent.changedTouches[0].pageX,
startY = e.originalEvent.changedTouches[0].pageY;
});
$("body").on("touchmove", '.babygroup-pickoff li', function (e) {
e.preventDefault();
moveEndX = e.originalEvent.changedTouches[0].pageX,
moveEndY = e.originalEvent.changedTouches[0].pageY,
X = moveEndX - startX,
Y = moveEndY - startY;
if (Math.abs(Y) > Math.abs(X) && Y > 0) {
num--;
if (num < 0) {
num = 9;
}
$(this).html(num);
} else if (Math.abs(Y) > Math.abs(X) && Y < 0) {
num++;
if (num > 9) {
num = 0;
}
$(this).html(num);
};
$(".babygroup-picker input").val($(".babygroup-picker li").eq(0).html() + $(
".babygroup-picker li ").eq(1).html() + $(".babygroup-picker li").eq(2).html());
});
</script>
</body>
</html>
引入
lodash
,非常好用的一个前端工具类库