H5 移动端 时间选择器

本选择器,自己填充内容(li的文本),只是做了一个大概的样式,其它的有需要者自己去改


<html>

<head>
<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<script type="text/javascript" src="iscroll.js"></script>
<script type="text/javascript" src="zepto.js"></script>

<style type="text/css">
.pic{
 margin: auto;  
  position: absolute;  
  top: 0; bottom: 0; right: 0;  
}


.date_picker{
width:90%;
margin:0 auto;
border:1px solid #ccc;
min-height:245px;
background:#jjj;
position:relative;
}




.date_picker_title{
width:100%;
height:80px;
line-height:80px;
border-bottom:1px solid #ccc;
text-align:center;
margin-bottom:5px;
}


ul{
list-style:none;
margin:0;
padding:0;
}
ul li{
width:100%;
height:60px;
line-height:60px;
border-bottom:1px solid #ccc;
text-align:center;
}
.date_picker .on{
background:#aaa;
}




#date_list{
height:183px;
overflow:auto;
}




</style>
</head>


<body>
<div class="filter">




</div>




<div class="date_picker"  >
<div class="date_picker_title" >时间选择器</div>
<div id="date_list">
<ul>
    <li></li>


<li class="on">8-30</li>
    <li>9-1</li>
    <li>9-2</li>
    <li>9-3</li>
    <li>9-4</li>
    <li>9-5</li>
    <li>9-6</li>
    <li></li>


</ul>
</div>


</div>




</body>
</html>
<script>
window.οnlοad=function(){
var myScroll;
var liHeight=$("#date_list ul li").height();
var currentLI=0;
var a=0;
function loaded () {
myScroll = new IScroll('#date_list', { mouseWheel: true });

myScroll.on('scrollStart', function () {
$("#date_list ul li").removeClass("on");


});

myScroll.on('scrollEnd', function () {
//alert("scroll end!!")
a=Math.round(Math.abs(this.y)/liHeight)+1

$("#date_list ul li").eq(a).addClass("on");

console.log("a=", a);
currentLI= parseInt(((this.y*-1)-(61*2))/liHeight)+1;
console.log("currentLI="+currentLI);

myScroll.scrollTo(0, -1*(a-1)*61, IScroll.utils.ease.elastic);


console.log($("#date_list ul li[class='on']").html())


if ( this.x < -1000 ) {
// do something

}
});

  }




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





loaded();


}






</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值