css3 html5 手机设备 列表的弹回和加速移动
2024-10-07 20:45:46
<style type="text/css">
* {
margin: 0;
padding: 0;
} .min {
width: 350px;
height: 400px;
overflow: hidden;
} .min ul {
list-style: none;
display: block;
} .min ul li {
height: 30px;
}
</style>
<body>
<div class="min">
<ul>
<li>21212125</li>
<li>12</li>
<li>343</li>
<li>5345</li>
<li>53</li>
<li>435</li>
<li>ert</li>
<li>345</li>
<li>eg</li>
<li>grrrrrr</li>
<li>3453</li>
<li>ret</li>
<li>345</li>
<li>21212125</li>
<li>456</li>
<li>56</li>
<li>rt</li>
<li>67</li>
<li>768</li>
<li>789</li>
<li>dfg</li>
<li>789</li>
<li>21212gggggg125</li>
<li>21212125</li>
<li>789</li>
<li>eeqqqqqqqq</li>
<li>789</li>
<li>gf</li>
<li>ttgg</li>
<li>sdf</li>
<li>789</li>
<li>21212125</li>
<li>dgdgdgd</li>
<li>90</li>
<li>21212125</li>
<li>-90</li>
<li>21212125</li>
<li>21212125</li>
<li>2121902125</li>
<li>90-</li>
<li>21212125</li>
<li>end</li>
<li>gf</li>
<li>ttgg</li>
<li>sdf</li>
<li>789</li>
<li>21212125</li>
<li>dgdgdgd</li>
<li>90</li>
<li>21212125</li>
<li>-90</li>
<li>21212125</li>
<li>21212125</li>
<li>2121902125</li>
<li>90-</li>
<li>21212125</li>
<li>end</li>
<li>gf</li>
<li>ttgg</li>
<li>sdf</li>
<li>789</li>
<li>21212125</li>
<li>dgdgdgd</li>
<li>90</li>
<li>21212125</li>
<li>-90</li>
<li>21212125</li>
<li>21212125</li>
<li>2121902125</li>
<li>90-</li>
<li>21212125</li>
<li>end</li>
<li>gf</li>
<li>ttgg</li>
<li>sdf</li>
<li>789</li>
<li>21212125</li>
<li>dgdgdgd</li>
<li>90</li>
<li>21212125</li>
<li>-90</li>
<li>21212125</li>
<li>21212125</li>
<li>2121902125</li>
<li>90-</li>
<li>21212125</li>
<li>end</li>
<li>gf</li>
<li>ttgg</li>
<li>sdf</li>
<li>789</li>
<li>21212125</li>
<li>dgdgdgd</li>
<li>90</li>
<li>21212125</li>
<li>-90</li>
<li>21212125</li>
<li>21212125</li>
<li>2121902125</li>
<li>90-</li>
<li>21212125</li>
<li>end</li>
<li>gf</li>
<li>ttgg</li>
<li>sdf</li>
<li>789</li>
<li>21212125</li>
<li>dgdgdgd</li>
<li>90</li>
<li>21212125</li>
<li>-90</li>
<li>21212125</li>
<li>21212125</li>
<li>2121902125</li>
<li>90-</li>
<li>21212125</li>
<li>end9999999999999</li>
</ul>
</div>
</body>
<script>
$.fn.touchEvn = function () { return this.each(function () {
var $this = $(this);
var $touchtarge = $this.children('ul');
var _ = this;
_.startY = 0;
//最高
_.maxHeight = $touchtarge[0].scrollHeight - $this.height();
_.StartSpanTime = undefined;
_.LastTop = 0;
$touchtarge.on('touchstart', function (e) {
_.startY = event.targetTouches[0].pageY;
_.StartSpanTime = event.timeStamp; }).on('touchmove', function (e) {
$(this).css({ 'transition': 'none' });
//移动的长度
var len = _.startY - event.targetTouches[0].pageY;
//最终的长度
len = (_.LastTop + len) * -1;
$(this).css('marginTop', len); }).on('touchend', function (e) {
//最终停留的位置
_.LastTop = _.LastTop + (_.startY - event.changedTouches[0].pageY);
$(this).css({ 'transition': 'margin 1s', 'transition-timing-function': 'cubic-bezier(0.1,0.3,0.5,1)' });
if (_.LastTop < 0) {
_.LastTop = 0;
$(this).css('marginTop', _.LastTop);
} else if (_.LastTop > _.maxHeight) {
_.LastTop = _.maxHeight;
$(this).css('marginTop', _.LastTop * -1);
}
else {
//减速行驶
var endLen = _.checkSpeen(event.timeStamp - _.StartSpanTime, _.startY - event.changedTouches[0].pageY);
_.LastTop = _.LastTop + endLen;
$(this).css('marginTop', _.LastTop * -1);
}
}).on('transitionend',function(){
if (_.LastTop < 0) {
_.LastTop = 0;
$(this).css('marginTop', _.LastTop);
} else if (_.LastTop > _.maxHeight) {
_.LastTop = _.maxHeight;
$(this).css('marginTop', _.LastTop * -1);
}
}); //计算减速行驶距离
_.checkSpeen = function (t, s, maxlen) {
var v = s / t;
//惯性距离
var len = 800 * v / 11;
if (len > maxlen) {
return maxlen;
}
else {
return len;
}
} });
} $('.min').touchEvn();
</script>
最新文章
- iOS小Tip之查看FPS
- __attribute__((packed))作用
- 开发 web 桌面类程序几个必须关注的细节
- php生成对象的研究
- 蓝牙BLE MTU规则与约定
- 配置apache以fastcgi运行php
- WPF 之 布局(二)
- Maven最佳实践:管理依赖
- jenkis编译报错:需要class,interface或enum
- asp.net中为什么修改了配置文件后我们不需要重启IIS
- @CacheEvict(value = { ";"; })
- CSS传统布局之布局模型
- 背景图片蒙上一层颜色(背景图片无法用rgba调整透明度!)
- 【一本通1329:【例8.2】细胞&;&;洛谷P1451 求细胞数量】
- prometheus监控
- postgre中类似oracle的sql%rowcount用法
- hdu2602 Bone Collector 01背包
- jQuery AJAX方法 前台往后台传数据
- bzoj1911 [Apio2010]特别行动队commando
- python使用关键字爬取url