常见的移动端兼容问题和解决方案

移动端兼容问题

1、禁止iOS识别长串数字为电话

解决方案:<meta content="telephone=no" name="format-detection" />

2、禁止iOS弹出各种操作窗口

解决方案:-webkit-touch-callout:none

3、禁止Android手机识别邮箱

解决方案:<meta content="email=no" name="format-detection" />

4、禁止iOS和Android用户选中文字

解决方案:-webkit-user-select:none

5、iOS下取消input在输入的时候英文首字母的默认大写

解决方案:<input autocapitalize="off" autocorrect="off" />

6、Android下取消输入语音按钮

解决方案:input::-webkit-input-speech-button {display: none}

7、在移动端修改难看的点击的高亮效果,iOS和安卓下都有效

解决方案:* {-webkit-tap-highlight-color:rgba(0,0,0,0);}

8、iOS下input为type=button属性disabled设置true,会出现样式文字和背景异常问题

解决方案:使用opacity=1;

9、input为fixed定位,在iOS下input固定定位在顶部或者底部,在页面滚动一些距离后,点击input(弹出键盘),input位置会出现在中间位置

解决方案:内容列表框也是fixed定位,这样不会出现fixed错位的问题

10、移动端字体小于12px使用四周边框或者背景色块,部分安卓文字偏上bug问题

解决方案:可以使用整体放大1倍(width、height、font-size等等),再使用transform缩放

11、在移动端图片上传图片兼容低端机的问题

解决方案:input 加入属性accept="image/*" multiple

12、在Android上placeholder文字设置行高会偏上

解决方案:input有placeholder情况下不要设置行高

13、overflow: scroll或auto;在iOS上滑动卡顿的问题

解决方案:加入-webkit-overflow-scrolling: touch;

14、iOS中日期如:2022-02-22 00:00:00格式的时间转时间戳不成功

解决方案:需要将时间中的'00:00:00去除之后才能转为时间戳'

15、iOS中需要将时间格式转为/,如:2022/02/22

let date = '2022-02-22';
let dateStr = date.replace(/-/g, '/'); // 2022/02/22

16、移动端click300ms延时响应

解决方案:使用Fastclick

window.addEventListener( "load", function() {
    
     
    FastClick.attach( document.body ); 
}, false );

17、移动端1px边框问题

解决方案:原先元素的border去掉,然后利用:before或者:after重做border,并transform的scale缩小一半,原先的元素相对定位,新做的border绝对定位

.border-1px{
    
     
    position: relative; 
    border:none; 
}

.border-1px:after{
    
    
    content: '';
    position: absolute; 
    bottom: 0;
    background: #000;
    width: 100%; 
    height: 1px;
    -webkit-transform: scaleY(0.5);
    transform: scaleY(0.5);
    -webkit-transform-origin: 0 0;
    transform-origin: 0 0; 
}

猜你喜欢

转载自blog.csdn.net/weixin_45215308/article/details/132701775