这可能看起来很随意,但我花了很长时间才能做到这一点。
我在IFRAME&中加载本地HTML文件我使用
启用水平导航overflow-x:scroll;overflow-y:hidden;
所以,我想知道当前的水平滚动条位置
var Iframe = document.getElementById("IframeId");
var pos = Iframe.scrollLeft;
&
vat pos = Iframe.document.body.scrollLeft;
两者都不适合我。帮我解决这个问题
答案 0 :(得分:3)
body
位于iframe
窗口内,而不在iframe
元素内。你可以参考这样的正确元素:
var Iframe = document.getElementById("IframeId").contentWindow;
var pos = Iframe.document.body.scrollLeft;
使用frames
集合的更多跨浏览器方式:
var Iframe = window.frames['IframeId'];
var pos = Iframe.document.body.scrollLeft;
修改强>
在IE10中,scrollLeft
属性需要从document.documentElement
读取,因此:
var pos = Iframe.document.documentElement.scrollLeft;
答案 1 :(得分:-1)
您可以调整iframe的滚动条。
iframe{ width: XXpx; height: XXpx; overflow-x: auto; overflow-y: hidden; }
试试这个。