Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <html>
    <head>
        <title>JS debounce</title>
        <link href="https://fonts.googleapis.com/css2?family=Jua&family=Roboto:[email protected]&display=swap" rel="stylesheet"> 
        <link rel="stylesheet" href="./assets/css/main.css">
    </head>
    <body>
        <main>
            <div class="card blue">
                <h1>JS debounce</h1>
                <input type="text" onkeyup="processChanges()" />
                <button onclick="processChanges()">Click me</button>
            </div>
        </main>
    </body>
</html>
              
            
!

CSS

              
                /* layout relevant styles */
html, body
    width: 100%
    height: 100%
    margin: 0
  
main
    display: grid
    height: 100%
    grid-template-columns: auto 33% auto
    grid-template-rows: auto auto auto
  
.card
    display: grid
    grid-template-columns: 100%
    grid-column: 2
    grid-row: 2



/* other styles */
.card
    padding: 50px
    color: #fff
    border-radius: 20px
    box-sizing: border-box
    font-family: Roboto, sans-serif
    background: rgb(0,174,239)
    background: linear-gradient(135deg, rgba(0,174,239,1) 20%, rgba(45,56,138,1) 100%)

    h1
        margin: 0 
        font-size: 3rem
        font-weight: lighter
        text-align: center
    
    input
        width: auto
        height: 50px
        border-radius: 25px
        border: 0
        line-height: 50px
        padding: 0 20px
        font-size: 1.5rem
        font-family: Roboto, sans-serif
        outline: none

    button
        width: 240px
        height: 50px
        border-radius: 25px
        border: 2px solid #fff
        line-height: 50px
        text-align: center
        font-size: 1.5rem
        color: #fff
        text-decoration: none
        margin-top: 10px
        position: relative
        box-sizing: border-box
        justify-self: center
        background: transparent
        cursor: pointer
        font-family: Roboto, sans-serif
        outline: none

        &:hover
            background: #ffffff
            color: #000
            &::after
                right: 10px

        &::after
            content: ">"
            font-family: "Jua"
            position: absolute
            right: 15px
            transition: right 1s ease

a, a:hover
    transition: all 0.3s ease
              
            
!

JS

              
                function debounce(func, timeout = 300){
  let timer;
  return (...args) => {
    clearTimeout(timer);
    timer = setTimeout(() => { func.apply(this, args); }, timeout);
  };
}
  
function saveInput(){
  console.log('Saving data');
}

const processChanges = debounce(() => saveInput());
              
            
!
999px

Console