Lazy loading (rolling load)

canILoad: function (elem, Method) {
             var scrollDistance = document.body.scrollTop || document.documentElement.scrollTop;    // Get scrolling distance 
            var availableViewHeight = document.body.clientHeight;    // visible area height 
            var advancedDistance = 30;   // advance how many starts loading 
            
            IF (scrollDistance + availableViewHeight> elem.offsetTop - advancedDistance) {
                 IF (! {elem.isLoad) 
                    console.log ( "loaded successfully" );
                     IF ( typeof (Method,) === "function" ) {
                        Method (); 
                        elem.isLoad = to true ; 
                    } the else { 
                        the console.log ( "fail to load" ); 
                    } 
                }       
            } 
        }

 

Guess you like

Origin www.cnblogs.com/JianXin1994/p/11588626.html