小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

解決部分iphone上使用iframe標簽變寬的異常情況

 Coder編程 2021-10-30

iframe在部分iphone手機上變寬

如下圖:

 

 

 百度查了很多也試了很多,最后的解決方式如下:

第一種:

我使用的是VUE

html代碼:

<!-- 對于iphone中scrolling必須是no,不要擔心一定會滾動的,對于安卓手機scrolling則是auto,否則在安卓移動端不會滾動 -->
<iframe id="iframe1" class="iframeCss" height="100%" width="100%" :src="url" frameborder="0" :scrolling="type"></iframe>

css代碼:

 .iframeCss {
    min-width: 100%;
    width: 3.75rem !important; //設(shè)置iframe寬度,這個也尤其重要
  }

 

JavaScript代碼:

//onload方法在mounted()中執(zhí)行
  onload() {
    //獲取iframe標簽
      var iframe = document.getElementById('iframe1')
      let _this = this
      iframe.onload = function() {
     // 判斷當前的移動端是否是蘋果系統(tǒng)
        var u = navigator.userAgent
        var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
        if (isiOS) {
          try {
       // 這個try catch可有可無
       // 我測試了幾遍自己程序,沒有這一塊代碼的話,頁面第一次展示的時候有可能頁面會變寬一下,但是很快就又正常了,看著變寬只是一個過渡,我不知道是我手機問題還是其他問題,這個沒有深究
            document.body.style.width = (window.screen.availWidth / document.body.clientWidth) * 100 + '%'
            var iframebody = iframe.contentWindow.document.body
            iframebody.style.width = document.body.clientWidth + 'px'
            // eslint-disable-next-line no-empty
          } catch (error) {}
      // 這是設(shè)置iframe的scrolling屬性
          _this.type = 'no'
        }
        window.scrollTo(0, 0)
      }
    }

第二種:(這是補充的內(nèi)容,優(yōu)先考慮使用這種

html代碼:

<div class="header"></div>
<div class="swapper">
    <!-- scrolling必須是auto或者yes,iframe才能滾動,不區(qū)分安卓和蘋果 -->
      <iframe id="iframe1" class="iframeCss" height="100%" width="100%" :src="linkurl" frameborder="0" scrolling="auto"></iframe> 
</div>

css代碼:

.header {
     height: 0.44rem;
    width: 100%;
    background-color: #09b6f2;
    position: fixed;
    z-index: 2000;
    top: 0;
    left: 0;
}
.swapper {
    position: fixed;
    top: 0.44rem;
    left: 0;
    height: 100%;
    width: 100%;
    -webkit-overflow-scrolling: touch;
    overflow-y: scroll;
}

沒有JavaScript代碼需要處理;

這樣能保證頭部固定,iframe的內(nèi)容也可以滾動,不用處理不同移動端的情況。

圖片和內(nèi)容參考地址:https://www.cnblogs.com/wuzhiquan/p/5358731.html

 

 

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多