.user-select-none { -webkit-user-select: none; /* Chrome all / Safari all */ -moz-user-select: none; /* Firefox all (移动端不需要) */ -ms-user-select: none; /* IE 10+ */ }
18. 移动端取消touch高亮效果在做移动端页面时,会发现所有a标签在触发点击时或者所有设置了伪类 :active 的元素,默认都会在激活状态时,显示高亮框,如果不想要这个高亮,那么你可以通过css以下方法来进行全局的禁止:
html { -webkit-tap-highlight-color: rgba(0, 0, 0, 0); }
但这个方法在三星的机子上无效,有一种妥协的方法是把页面非真实跳转链接的a标签换成其它标签,可以解决这个问题。
19. 如何禁止保存或拷贝图像(IOS)通常当你在手机或者pad上长按图像 img ,会弹出选项 存储图像 或者 拷贝图像,如果你不想让用户这么操作,那么你可以通过以下方法来禁止:
img { -webkit-touch-callout: none; }
20.模拟按钮hover效果移动端触摸按钮的效果,可明示用户有些事情正要发生,是一个比较好体验,但是移动设备中并没有鼠标指针,使用css的hover并不能满足我们的需求,还好国外有个激活css的active效果,代码如下,
<!DOCTYPE html> <html> <head> <meta charset=”utf-8″> <meta content=”width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no” name=”viewport”> <meta content=”yes” name=”apple-mobile-web-app-capable”> <meta content=”black” name=”apple-mobile-web-app-status-bar-style”> <meta content=”telephone=no” name=”format-detection”> <meta content=”email=no” name=”format-detection”> <style type=”text/css”> a{-webkit-tap-highlight-color: rgba(0,0,0,0);} .btn-blue{display:block;height:42px;line-height:42px;text-align:center;border-radius:4px;font-size:18px;color:#FFFFFF;background-color: #4185F3;} .btn-blue:active{background-color: #357AE8;} </style> </head> <body> <div class=”btn-blue”>按钮</div> <script type=”text/javascript”> document.addEventListener(“touchstart”, function(){}, true) </script> </body> </html>
兼容性ios5+、部分android 4+、winphone 8
要做到全兼容的办法,可通过绑定ontouchstart和ontouchend来控制按钮的类名
<!DOCTYPE html> <html> <head> <meta charset=”utf-8″> <meta content=”width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no” name=”viewport”> <meta content=”yes” name=”apple-mobile-web-app-capable”> <meta content=”black” name=”apple-mobile-web-app-status-bar-style”> <meta content=”telephone=no” name=”format-detection”> <meta content=”email=no” name=”format-detection”> <style type=”text/css”> a{-webkit-tap-highlight-color: rgba(0,0,0,0);} .btn-blue{display:block;height:42px;line-height:42px;text-align:center;border-radius:4px;font-size:18px;color:#FFFFFF;background-color: #4185F3;} .btn-blue-on{background-color: #357AE8;} </style> </head> <body> <div class=”btn-blue”>按钮</div> <script type=”text/javascript”> var btnBlue = document.querySelector(“.btn-blue”); btnBlue.ontouchstart = function(){ this.className = “btn-blue btn-blue-on” } btnBlue.ontouchend = function(){ this.className = “btn-blue” } </script> </body> </html>
21.屏幕旋转的事件和样式事件
window.orientation,取值:正负90表示横屏模式、0和180表现为竖屏模式;