jQuery 中的 $('iframe').ready() 方法如何工作?
以下是一個示例,其中 iframe 大小大於頁面。每當 iframe 載入時,我們都將使用 jQuery 滾動到頁面的頂部 -
示例
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $('iframe').ready(function(){ $(window).scrollTop(0); }); }); }); </script> </head> <body> <iframe frameborder="2" height="900" id="iframe" align="top" src="https://www.qries.com" width="900" ></iframe><br> <button>Loop through each image</button> </body> </html>
廣告