地质所 沉降监测网建设项目
zmk
2024-05-22 28e168f05d3eb48223e69064188c6fce786442d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
( function( $ ) {
    $.fn.scrollLoad = function( options ) {
    
        var defaults = {
            url : '',
            data : '',
            ScrollAfterHeight : 90,
            onload : function( data, itsMe ) {
                alert( data );
            },
            start : function( itsMe ){},
            continueWhile : function() {
                return true;
            },
            getData : function( itsMe ) {
                return '';
            }
        };
 
        for( var eachProperty in defaults ) {
            if( options[ eachProperty ] ) {
                defaults[ eachProperty ] = options[ eachProperty ];
            }
        }
 
        return this.each( function() {
            this.scrolling = false;
            this.scrollPrev = this.onscroll ? this.onscroll : null;
            $( this ).bind( 'scroll', function ( e ) {
                if( this.scrollPrev ) {
                    this.scrollPrev();
                }
                if( this.scrolling ) return;
                //var totalPixels = $( this ).attr( 'scrollHeight' ) - $( this ).attr( 'clientHeight' );
                if( Math.round( $( this ).prop( 'scrollTop' ) / ( $( this ).prop( 'scrollHeight' ) - $( this ).prop( 'clientHeight' ) ) * 100 ) > defaults.ScrollAfterHeight ) {
                    defaults.start.call( this, this );
                    this.scrolling = true;
                    $this = $( this );
                    $.ajax( { url : defaults.url, data : defaults.getData.call( this, this ), type : 'post', success : function( data ) {
                        $this[ 0 ].scrolling = false;
                        defaults.onload.call( $this[ 0 ], data, $this[ 0 ] );
                        if( !defaults.continueWhile.call( $this[ 0 ], data ) ) {
                            $this.unbind( 'scroll' );
                        }
                    }});
                }
            });
        });
    }
})( jQuery );