安卓瀏覽器看背景圖片,有些設備會模糊
- 解決方案:將背景圖片放大為div的2X倍(一般為兩倍),背景圖盡量高清且大於目標div的尺寸
/*原背景(div寬高都為100px)*/
.div{
background:url(../../XX.png) no-repeat center center;
background-size: 100px 100px;display:inline-block;
}
/*兼容后的背景*/
.div{
background:url(../../XX.png) no-repeat center center;
background-size: 200px 200px;display:inline-block;
}
/*或者*/
.div{
background:url(../../XX.png) no-repeat center center;
background-size: contain;
}
圖片加載很慢
- 解決方案:1.使用Canvas繪制圖片進行預加載;
2.使用Lazy Load插件
/*方案1*/
/* 獲取圖片的base64碼
* @param {obj}img圖片dom對象
* */
function getBase64Image(img) {
let canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
let ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height); //繪制相同圖片
return canvas.toDataURL("image/png"); //轉換成base64數據
}
<!--需要預加載的圖片-->
<save-img-base64>
<img src="../../assets/1.png"/>
<img src="../../assets/2.png"/>
<img src="../../assets/3.png"/>
</save-img-base64>
/*方案2*/
/*加載Lazy Load插件,其為jQuery的一個庫因此也要加載jQuery插件*/
<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.lazyload.js" type="text/javascript"></script>
<img src="img/grey.gif" data-original="img/example.jpg" width="640" heigh="480">
$("img.lazy").lazyload(threshold : 200);
/*當用戶禁用JavaScript時默認顯示的圖像
<img src="img/grey.gif" data-original="img/example.jpg" width="640" heigh="480">
<noscript><img src="img/example.jpg" width="640" heigh="480"></noscript>
<script type="text/javascript"></script>$("img.lazy").show().lazyload();</script>
手機中網頁的放大和縮小
- 解決方案:禁用用戶的縮放功能
<meta name="viewport" content="user-scalable=0"/>
格式的自動識別
- 解決方案:禁用自動識別頁面中的格式
<meta name="format-detection" content="telephone=no">
移動端Gps定位
- 解決方案:引用百度地圖的api
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body, html {
width: 100%;
height: 100%;
margin: 0;
font-family: "微軟雅黑";
font-size: 14px;
}
#allmap {
width: 100%;
height: 500px;
}
</style>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=wqBXfIN3HkpM1AHKWujjCdsi"></script>
<title>獲取當前所在地址,不顯示地圖</title>
</head>
<body>
<!--<div id="allmap"></div>-->
<!--不顯示地圖-->
<div id="allmap" style="display:none"></div>
</body>
</html>
<script type="text/javascript">
$(function () {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, locationError);
} else {
alert("你的瀏覽器不支持 GeoLocation.");
}
});
//定位成功時,執行的函數
function showPosition(position) {
// 百度地圖API功能
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398, 39.897445);
map.centerAndZoom(point, 12);
var geoc = new BMap.Geocoder();
translateCallback = function (res) {
alert(res.points.length);
$.each(res.points, function (index, val) {
var point = val;
alert(point.lng + "," + point.lat);
var marker = new BMap.Marker(point);
map.addOverlay(marker);
map.setCenter(point);
geoc.getLocation(point, function (rs) {
var addComp = rs.addressComponents;
alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
//var infoWindow = new BMap.InfoWindow(sContent);
//map.openInfoWindow(infoWindow, point);
});
});
}//(point);
var convertor = new BMap.Convertor();
var points = new Array();
points.push(point);
//translate(points: Array<BMap.Point>, from: number, to: number, callback: function)//callback返回是一個對象Object,TranslateResults類型
//TranslateResults:status,points
//參照:JavaScript API-服務類 Convertor TranslateResults http://lbsyun.baidu.com/cms/jsapi/reference/jsapi_reference.html#a7b49
//其中狀態碼可參照:WEB服務API-坐標轉換API http://lbsyun.baidu.com/index.php?title=webapi/guide/changeposition
convertor.translate(points, 1, 5, translateCallback);
}
// 定位失敗時,執行的函數
function locationError(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
alert("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
alert("Location information is unavailable.");
break;
case error.TIMEOUT:
alert("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
alert("An unknown error occurred.");
break;
}
}
</script>
上下拉動滾動條時卡頓、慢
body {
-webkit-overflow-scrolling:touch;
overflow-scrolling: touch;
}
是否允許用戶復制文本
Element {
-webkit-user-select:none;
-moz-user-select:none;
-khtml-user-select:none;
user-select:none;
}
長時間按住頁面出現閃退
element {
-webkit-touch-callout:none;
}
iphone及ipad下輸入框默認內陰影
Element{
-webkit-appearance:none;
}
i os和android下觸摸元素時出現半透明灰色遮罩
Element {
-webkit-tap-highlight-color:rgba(255,255,255,0)
}
active兼容處理 即 偽類 :active 失效
- 解決方案:js給 document 綁定 touchstart 或 touchend 事件
document.addEventListener('touchstart',function(){},false);
webkit mask 兼容處理
if('WebkitMask'indocument.documentElement.style){
/*支持*/
}
else{
/*不支持*/
}
旋轉屏幕時,字體大小自動調整的問題
html, body, form, fieldset, p, div, h1, h2, h3, h4, h5, h6{
-webkit-text-size-adjust:100%;
}
transition閃屏
/設置內嵌的元素在3D 空間如何呈現:保留3D /
-webkit-transform-style: preserve-3d;
/ 設置進行轉換的元素的背面在面對用戶時是否可見:隱藏 /
-webkit-backface-visibility:hidden;
圓角bug
background-clip: padding-box;
h5網站input 設置為type=number的問題
- 解決方案:解決max-length和部分手機樣式問題
functioncheckTextLength(obj, length) {
if(obj.value.length > length) {
obj.value = obj.value.substr(0, length);
}
}
input[type=number] {
-moz-appearance:textfield;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance:none;
margin:0;
}
IOS移動端click事件300ms的延遲響應
-解決方案:使用fastclick
window.addEventListener( "load", function() {
FastClick.attach( document.body );
}, false );
點擊穿透問題
- 解決方案:使用touch替代click,避免混用.
h5底部輸入框被鍵盤遮擋問題
<script src="jquery.js" type="text/javascript"></script>
var oHeight = $(document).height(); //瀏覽器當前的高度
$(window).resize(function(){
if($(document).height() < oHeight){
$("#footer").css("position","static");
}else{
$("#footer").css("position","absolute");
}
});
自動適應屏幕寬度
<meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=0">
在pc端的基礎上手動調節移動端的布局
/*max-width:最大寬度以下的布局為..min-width:最小寬度以上的布局為: 具有覆蓋效果*/
@media (max-width: 720px)
html {
font-size: 62.5%;
}
參考文檔
https://www.cnblogs.com/mazhaokeng/p/8461260.html
https://blog.csdn.net/dengboblog/article/details/53156570
https://blog.csdn.net/diqi77/article/details/54692920
https://www.cnblogs.com/zr123/p/8178740.html
