除非重新打开,否则 iframe 不会滚动
iframe won't scroll unless reopened
目前我正在开发一个位于我页面上的 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');
解决了。不得不搬家
existingStyle = frameFirstChild.getAttribute('style');
到 if 语句之前的内部,同时仍然包裹在 setTimeout()
内部
目前我正在开发一个位于我页面上的 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');
解决了。不得不搬家
existingStyle = frameFirstChild.getAttribute('style');
到 if 语句之前的内部,同时仍然包裹在 setTimeout()