除非重新打开,否则iframe不会滚动

时间:2015-03-24 23:15:43

标签: javascript iframe scroll ios8 mobile-safari

目前我正在处理一个位于我页面上的iframe的小部件。我可以选择让访问者通过iframe内的联系表单向我发送消息(比iframe长,因此需要滚动),但是,在iOS8上使用Chrome时,消息表单不会滚动,除非我关闭并重新打开小部件。有没有其他人遇到这个,或知道是什么原因造成的?

指示滚动iframe的代码如下:

frameDoc.body.firstChild.setAttribute(
   'style',
    ['width: 100%',
    'height: 100%',
    'overflow-x: hidden',
    'overflow-y: auto !important',
    '-webkit-overflow-scrolling: touch !important'].join(';')

);

好的新问题。当我打开iframe时,会添加'-webkit-overflow-scrolling:touch'样式,但是当我关闭它并重新打开时,样式会消失。如果我关闭它并重新打开它,则再次添加样式。我的代码如下:

if (
  existingStyle.indexOf('-webkit-overflow-scrolling') === -1) {
   frameFirstChild.setAttribute('style',
    `${existingStyle};-webkit-overflow-scrolling: touch;`);
  }

此语句包含一个setTimeout函数,但更改超时不会影响是否添加样式。我的var定义如下:

var frameFirstChild = this.getDOMNode().contentDocument.body.firstChild,
    existingStyle = frameFirstChild.getAttribute('style');

1 个答案:

答案 0 :(得分:0)

解决了这个问题。不得不搬家 {if}语句之前的existingStyle = frameFirstChild.getAttribute('style');内部,同时仍包含在setTimeout()

相关问题