手机扫码看效果
不多说,直接上代码
- 111
- 222
- 333
- 444
- 555
- 666
- 777
- 888
- 999
- 000
- aaa
- bbb
- ccc
- ddd
- eee
- fff
- ggg
- hhh
- iii
- jjj
- kkk
- lll
- mmm
- nnn
- ooo
- ppp
- qqq
*{ margin: 0; padding: 0; border: 0;}ul{ list-style: none;}li{ line-height: 2em; border-bottom: 1px solid #eee; width: 100%; text-indent: 2em;}
var UL = document.getElementById('Ul');var moves = true;function Alert(ev){ if(moves) alert(ev.target.innerHTML)}UL.addEventListener('touchmove',function(){ moves = false; UL.addEventListener('touchend',function(){ moves = true; })})UL.addEventListener('touchend', Alert)
原理:
1. 设置一个变量moved来标识是否有移动过,初始值为false;
2. 绑定touchend事件,将moved置为true;
3. 绑定touchmove事件,将moved置为false;
4. 在touchmove事件函数中继续绑定touchend事件,再将moved置为true
---恢复内容结束---