var userSelection, ss; if (window.getSelection) { //现代浏览器 userSelection = window.getSelection(); } else if (document.selection) { //IE浏览器 考虑到Opera,应该放在后面 userSelection = document.selection.createRange(); } if (!(ss = userSelection.text)) { ss = userSelection; }
目前在电脑上能用。移动端(uc)不能使用。
[移动开发]html5 手指触摸滑动事件[改进代码](jquery)
http://blog.sina.com.cn/s/blog_591e70ee0100tbdr.html
//假定接受手指触摸事件的Dom对象id是"touchBox" document.getElementById("touchBox").addEventListener("touchstart", touchStart, false); document.getElementById("touchBox").addEventListener("touchmove", touchMove, false); document.getElementById("touchBox").addEventListener("touchend", touchEnd, false); function touchStart(event){ var touch = event.touches[0]; startY = touch.pageY; } function touchMove(event){ var touch = event.touches[0]; endY = (startY-touch.pageY); if(scrollTopVal==0){ $("#touchBox").scrollTop((endY+100)); }else{ $("#touchBox").scrollTop(scrollTopVal+endY+100); } } function touchEnd(event){ scrollTopVal=$("#touchBox").scrollTop(); }