Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Throttling Example</title>
    <link rel="stylesheet" href="style.css" />
  </head>

  <body>
    <button id="btn" onclick="normalFunc(); apiWithThrottle();">Click Me!</button>
    <div class="first"><label>
      Number of times the button is clicked :
    </label>
    <input type="text" id="countClicks" value="0"></input></div>
    <div clas="second">
      <label>
        Number of times the API call will be made :
      </label>
      <input type="text" id="countCalls" value="0"></input>
    </div>
  </div>
    <script src="script.js"></script>
  </body>
</html>

              
            
!

CSS

              
                body {
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

div {
  padding: 15px;
}

button {
  margin-top: 20px;
  padding: 10px;
  width: 150px;
  font-size: 18px;
}

input {
  width: 30px;
  font-size: 20px;
  /* border: none; */
}

.first {
  margin-top: 20px;
}

              
            
!

JS

              
                var btn = document.getElementById("btn"); // Query Selector for the Button

let i = 1; // To track number of Clicks on the Button
let j = 1; // To track number of API calls being made

// Normal Function which increments number of clicks
// Called on Clicking the Button
const normalFunc = () => {
  document.getElementById("countClicks").value = i++;
  console.count("Normal Function Call");
};

// Function to be throttled (API calls)
const apiCallFunc = () => {
  document.getElementById("countCalls").value = j++;
  console.count("Throttled Function");
};

// The Throttle Function
const throttle = (fn, limit) => {
  let flag = true;
  return function () {
    if (flag) {
      fn();
      flag = false;
      setTimeout(() => {
        flag = true;
      }, limit);
    }
  };
};

// Called on clicking the Button
const apiWithThrottle = throttle(apiCallFunc, 1000);

              
            
!
999px

Console