function throttle function throttle

// function throttling var canRun = true ; document. getElementById( "throttle"). onscroll = function ( ) { if( !canRun) { // determine whether it is idle, if it is executing, return directly return ; } canRun = false ; setTimeout( function ( ) { console. log( "Function throttling") ; canRun = true ; }, 300) ; };

// function debounce var timer = false ; document. getElementById( "debounce"). onscroll = function ( ) { clearTimeout(timer) ; // clear unexecuted code, reset back to initialization state timer = setTimeout( function ( ) { console. log( "Function debounce") ; }, 300) ; };

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325303566&siteId=291194637