简体   繁体   English

如果用户滚动到底部,请加载iframe

[英]Load iframe if user scrolled to bottom

I'm building a HTML website where I would like to load an iframe if the user scrolled nearly to the bottom. 我正在建立一个HTML网站,如果用户几乎滚动到底部,我想在其中加载iframe。 (The iframe contains a lot of JavaScript heavy follow me widgets that are slowing down the website if they would be loaded directly) (iframe包含许多JavaScript繁重的“ 跟我来”小部件,如果直接加载它们会减慢网站速度)

How can that be done? 那怎么办?

Thanks. 谢谢。 Uli 乌里

use .scroll() 使用.scroll()

Like so: 像这样:

$(window).scroll(function() {   
   if(($(window).scrollTop() + $(window).height()) == $(document).height()) {
       $('div').append('<iframe></iframe>');
   }
});​

Here's a fiddle with an example - http://jsfiddle.net/vRLsg/ 这是一个带有示例的小提琴-http: //jsfiddle.net/vRLsg/

You can calculate the position when you scroll 滚动时可以计算位置

$('body').scroll(function(){
    if ($('body').scrollTop() == $('body').height()){
       loadIframe();
    }
});

看看这个jsfiddle-我想它可以满足您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM