手机移动端页面 发表于 2018-11-10 | 分类于 HTML/CSS 300ms延迟时间流 那时的网页都是给 PC 用的,宽度是 1000px 左右 移动端页面会自动缩放,如320px缩放成980px来看960px的页面 双击是表示放大,单击是点击 单击会出现300ms延迟,如果300ms内再点击就是放大,否则是点击 BAT程序员解决单击出现300ms延迟用touchstart事件 导致一系列问题,所以造了fackclick.js库 解决方法12// 如今都是给移动端宽度写页面,不需要缩放,所以不需要也没有300ms延迟<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> 触屏事件触屏事件的应用12345678910111213141516171819202122232425262728293031323334353637383940414243444546<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <title>触屏事件</title> <style> .box{ width: 50vw; height: 50vh; background-color: green; } </style></head><body> <div class="box"></div> <script> var box = document.querySelector('.box') box.addEventListener('touchstart',function(){ console.log('开始摸了') }) box.addEventListener('touchcancel',function(){ console.log('取消触摸') }) box.addEventListener('touchend',function(){ console.log('摸完了') }) box.addEventListener('touchenter',function () { console.log('摸进去了') }) box.addEventListener('touchleave',function(){ console.log('摸出来了') }) box.addEventListener('touchmove',function () { console.log('边摸边动') }) </script></body></html> 触屏事件的写字小例子1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <title>触屏事件</title> <style> /*手机端初始化*/ *,*::after,*::before{ box-sizing: border-box; } img{ max-width: 100%; max-height: 100%; } body{ margin: 0; } .box{ width: 100vw; height: 100vh; background-color: green; } </style></head><body> <div class="box"></div> <script> var box = document.querySelector('.box') function addPoint(x,y) { let div = document.createElement('div') div.style.position = 'absolute' div.style.top = y + 'px' div.style.left = x + 'px' div.style.height = '5px' div.style.width = '5px' div.style.background = 'black' document.body.appendChild(div) } box.addEventListener('touchstart',function(e){ console.log('开始摸了') let {pageX,pageY} = e.touches[0] addPoint(pageX,pageY) }) </script></body></html>