Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
// 減緩呼叫function的時間
function debounce(func, wait = 20, immediate = true) {
  
  console.log('debounce~~~~in');
  var timeout;
  return function() {
    console.log('function~~~~in');
    var context = this, args = arguments;
    
    var later = function() {
      timeout = null;
      if (!immediate) func.apply(context, args);
    };
    
    var callNow = immediate && !timeout;
    
    clearTimeout(timeout);
    timeout = setTimeout(later, wait);
    
    if (callNow) func.apply(context, args);
  };
}
function handleShowImage(e){
//   console.log('handleShowImage');
//   console.timeEnd();
//   console.time();
}
// window.addEventListener('scroll', handleShowImage);
window.addEventListener('scroll', debounce(handleShowImage,0,true));
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers