2017-04-09 51 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>