防止手機瀏覽點擊輸入框自動放大

來源:互聯網
上載者:User

標籤:art   span   log   顯示   touch   view   new   start   eve   

1、設定meta屬性

<meta content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">

content屬性值 :

  width:可視地區的寬度,值可為數字或關鍵詞device-width;

  height:同width;

  intial-scale:頁面首次被顯示是可視地區的縮放層級,取值1.0則頁面按實際尺寸顯示,無任何縮放;

  maximum-scale=1.0, minimum-scale=1.0:可視地區的縮放層級,maximum-scale使用者可將頁面放大的程式,1.0將禁止使用者放大到實際尺寸之上;

  user-scalable:是否可對頁面進行縮放,no 禁止縮放。

2、蘋果為了提高Safari中網站的協助工具功能,屏蔽了Meta下的user-scalable=no功能。所以在iOS10下面,就算加上user-scalable=no,Safari瀏覽器也能支援手動縮放。所以只能用js加監聽事件來阻止手動縮放。

window.onload=function () {          document.addEventListener(‘touchstart‘,function (event) {              if(event.touches.length>1){                  event.preventDefault();              }          })          var lastTouchEnd=0;          document.addEventListener(‘touchend‘,function (event) {              var now=(new Date()).getTime();              if(now-lastTouchEnd<=300){                  event.preventDefault();              }              lastTouchEnd=now;          },false)      } 

 

防止手機瀏覽點擊輸入框自動放大

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.