h5開發中所遇到的兼容性及所遇到的常見問題

1. 移動端border1px問題html

 

<script>

var viewport = document.querySelector("meta[name=viewport]");
//下面是根據設備像素設置viewport
if (window.devicePixelRatio == 1) {
viewport.setAttribute('content', 'width=device-width,initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no');
}
if (window.devicePixelRatio == 2) {
viewport.setAttribute('content', 'width=device-width,initial-scale=0.5, maximum-scale=0.5, minimum-scale=0.5, user-scalable=no');
}
if (window.devicePixelRatio == 3) {
viewport.setAttribute('content', 'width=device-width,initial-scale=0.3333333333333333, maximum-scale=0.3333333333333333, minimum-scale=0.3333333333333333, user-scalable=no');
}
var docEl = document.documentElement;
var fontsize = 10 * (docEl.clientWidth / 320) + 'px';
docEl.style.fontSize = fontsize;

</script> web

2. 移動端滑動無效問題ide

<script>
  function GetSlideDirection(startX, startY, endX, endY) {
  var dy = startY - endY;
  //var dx = endX - startX;
  var result = 0;
  if(dy>0) {//向上滑動
  result=1;
  }else{//向下滑動
  result=2;
  }
   
  return result;
  }
   
  //滑動處理
  var startX, startY;
  document.addEventListener('touchstart',function (ev) {
  startX = ev.touches[0].pageX;
  startY = ev.touches[0].pageY;
  }, false);
   
  document.addEventListener('touchend',function (ev) {
  var endX, endY;
  endX = ev.changedTouches[0].pageX;
  endY = ev.changedTouches[0].pageY;
  var direction = GetSlideDirection(startX, startY, endX, endY);
  switch(direction) {
  case 0:
  break;
  case 1:
  // 向上
  window.location = "3-1.html";
  break;
  case 2:
  // 向下
  alert("down");
  break;
   
  default:
  }
 

}, false);post

 

  </script>

3. 移動端視屏videothis

    <video id="pc_video" style="object-fit: fill" src="../../video/pc.mp4" controls="controls" preload poster="../../img/pc/m.jpg" webkit-playsinline="true" playsinline="true"  x5-video-player-fullscreen="true" x5-video-orientation="portraint">
            </video>
spa

var pcVideo = document.getElementById('pc_video')
            pcVideo.onclick=function(){
                pcVideo.play()
                document.addEventListenerR("WeixinJSBridgeeady", function() {
                    pcVideo.play()
                }, false)
             }
scala

4. 移動端input喚起鍵盤會吧body內容頂上去
code

 

 

 

5. 去掉a的默認點擊效果xml

                a:active{      -webkit-tap-highlight-color: rgba(0, 0, 0, 0); }htm

                 input{      outline: none;   }

6.  調用手機回車鍵進行搜索

  1. <input id="keyword" placeholder="輸入關鍵字搜索"  type="search" />
  2. $("#keyword").on('keypress',function(e) {  
  3.                 var keycode = e.keyCode;  
  4.                 var searchName = $(this).val();  
  5.                 if(keycode=='13') {  
  6.                     e.preventDefault();    
  7.                     //請求搜索接口  
  8.                       
  9.                 }  
  10.          });
相關文章
相關標籤/搜索