有些网站的网页内容不是一次性加载完毕的,而是在鼠标向下滚动时动态加载的,这是怎么做到的呢?看下面代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
var loading = false ;
$(window).scroll( function (){
if ((($(window).scrollTop()+$(window).height())+250)>=$(document).height()){
if (loading == false ){
loading = true ;
$( '#loadingbar' ).css( "display" , "block" );
$.get( "load.php?start=" +$( '#loaded_max' ).val(), function (loaded){
$( 'body' ).append(loaded);
$( '#loaded_max' ).val(parseInt($( '#loaded_max' ).val())+50);
$( '#loadingbar' ).css( "display" , "none" );
loading = false ;
});
}
}
}); $(document).ready( function () {
$( '#loaded_max' ).val(50);
}); |
看官赏点饭钱可好?