2017-04-09 31 views
-2

有点新的HTML,我不知道该怎么去谷歌。如果可能,我想要做的是设置我的iFrame在页面加载时向下滚动100px。设置自动滚动量iFrame

+1

https://www.google.com/search?q=+set+my+iFrame+to+scroll+down+100px+when+the+page+is+loaded –

回答

0

您可以从iframe中获取window对象,并调用scrollTo()函数设置新值。例如:

<iframe id="myFrame" src="about:blank" frameborder="0"></iframe> 

<script> 
    // Listen to `load` event of main window 
    window.addEventListener('load', function (event) { 
     // Get the `window` object of `myFrame` element and assign to `iFrameWindow` variable 
     var iFrameWindow = myFrame.contentWindow; 

     // Add some virtual space to body element 
     iFrameWindow.document.body.style.height = '2048px'; 

     // Scroll the window. 
     iFrameWindow.scrollTo(0, 100); 
    }); 
</script>