【问题标题】:iframe gets displaced on iOS when dragged拖动时 iframe 在 iOS 上移位
【发布时间】:2016-08-26 04:16:55
【问题描述】:

我的网站上有一个 iframe,当您单击 Make an Appointment 按钮时会填充该 iframe。 iframe 包含一个带有多个输入字段的联系表单。

一切正常,但出于某种原因,在 iOS(iPad 和 iPhone 5/6 - 我测试了 Safari 和 Chrome)上,表单可以拖动到其容器的宽度和高度之外。它应该只能在 y 轴上滚动;就像在 Android 设备上一样。请看下面的截图。

我查看了许多关于 S/O 的帖子,但尚未找到任何与 iOS 设备/浏览器的这种特殊细微差别有关的 Q/A。

代码如下:

HTML:

<div id='button'><button id='contact'>MAKE AN APPOINTMENT</button></div>
    <div id="block"></div>
       <div id="iframecontainer">
           <a id='close' href='#'>X</a>
          <div id="loader"></div>
        <iframe></iframe>
    </div>

JQuery:

$('document').ready(function() {
  $('#contact').click(function () {
    $('#block').fadeIn();
    $('#iframecontainer').fadeIn();
    $('#header-wrapper').css("visibility", "hidden");
     var width = $(window).width();
    $('#iframecontainer iframe').attr('src', 'http://a-link-to-my-iframe.html');
    if (width > 850) {
        $('#iframecontainer').css('width', '790px');
        $('#iframecontainer').css('margin-left', '-395px');
    }
    else {
        $('#iframecontainer').css('width', '310px');
        $('#iframecontainer').css('margin-left', '-155px');
    }
    $('#iframecontainer iframe').load(function() {
         $('#loader').fadeOut(function() {
            $('iframe').fadeIn();
         });
     });
   });

还有,CSS:

#contact {
  color: #c2c2c2;
  background: #151515;
  border: 1px solid #c2c2c2;
  padding: 13px 26px;
  text-decoration: underline;
  font-family: inherit;
  letter-spacing: 2px;
  font-size: 18px;
  margin: 0 auto;
}

#iframecontainer {
  width:75%; 
  height: auto; 
  display: none; 
  position: fixed;
  -webkit-overflow-scrolling:touch;
  overflow-y: auto;
  height:600px;
  top: 10%; 
  background:#FFF; 
  border: 1px solid #666;
  border: 1px solid #555;
  box-shadow: 2px 2px 40px #222;
  z-index: 999999;
  left: 50%;
  margin-left: -395px;
}
#iframecontainer iframe { 
  width: 100%; 
  height: 600px; 
  position: absolute; 
  border: none; 
}
#loader { 
  width: 250px; 
  height: 250px; 
  margin:auto;
}
#block {
  background: #000; 
  opacity:0.6;  
  position: fixed; 
  width: 100%; 
  height: 100%; 
  top:0; 
  left:0; 
  display:none;
}​

这是我所指的屏幕截图:

是否有特定的方法可以在 iOS 设备上禁用此功能?

【问题讨论】:

    标签: javascript jquery ios css iframe


    【解决方案1】:

    尝试在 iframe 上添加 scrolling="no" 并更改一些 iframe CSS,例如,

    #iframecontainer iframe { 
      width: 1px;/* Make it a very small for your viewport */
      min-width:100%;/* Overwrite width. Let it decides the actual width of iframe */
      height: 600px; 
      position: absolute; 
      border: none; 
    }
    

    【讨论】:

    • scrolling="no" 我相信在 HTML5 中被贬低了。我会尝试 CSS 建议。
    • 更新:我尝试了上面的解决方案,但没有奏效。我需要能够在 y 轴上滚动表单。我希望在滚动时禁用这种类似“橡皮筋”的功能。
    猜你喜欢
    • 2019-01-24
    • 1970-01-01
    • 2017-05-12
    • 2013-01-25
    • 1970-01-01
    • 2016-03-23
    • 2021-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多