示例:jsfiddle
html:
<iframe id="frame" scrolling="no"></iframe>
js:
frame.contentWindow.document.write('scroll</br><div style="width:100px;height:100px;"><canvas id="cv"></canvas></div>');
var cv = frame.contentWindow.document.body.childNodes[2].childNodes[0];
var context = cv.getContext("2d");
cv.height = cv.width = 500;
context.fillStyle = "red";
context.rect(0, 0, 500, 500);
context.fill();
为什么这不适用于 android 4.2(也许在其他系统上)?为什么我可以在 scrolling="no"时滚动 iframe? 没有 Canvas ,一切都完美无缺。
最佳答案
请注意,iFrame 的 scrolling="no"
属性已从 HTML5 中删除。
也就是说,避免在 iFrame 中滚动的唯一真实可靠的方法是构建一个最大与 iFrame 本身一样大的内容。
我的经验表明,即使在尽可能多的浏览器上检查结果,无论如何它总是显示滚动条的配置....
关于javascript - 滚动属性不适用于 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33594278/