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 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

              
                <div class="description">
  <p>
    A brief set of demos for each of the methods offered by <a href="https://github.com/alexmacarthur/slide-element" target="_blank">slide-element</a>. To trigger then, click the respective button and watch it go. 
  </p>
</div>

<div class="container">
  <div class="example">
    <button id="downButton">Slide It Down</button>
    <div class="box" id="downExample">
      <span>These contents will open (go down). Because this example is only configured to go down, clicking this button again will make it jump back to an un-opened state and slide open again.</span>
    </div>
  </div>
  
  <div class="example">
    <button id="upButton">Slide It Up</button>
    
    <div class="box" id="upExample">
      <span>These contents will close (go up). Clicking this button again will only force the box to snap back to its original state and reply the animation again.</span>
    </div>
  </div>
    
  <div class="example">
    <button id="toggleButton">Toggle It</button>
    
    <div class="box" id="toggleExample">
      <span>These contents will toggle. For most use cases, this is probably the method you'll use in the wild. Clicking the button again will cause the box to open and closed based on its current state (obviously).</span>
    </div>
  </div>
</div>
              
            
!

CSS

              
                #downExample {
  display: none;
}

#upExample {
  display: block;
}

#toggleExample {
  display: none;
}







/* The styles below are only for making the demo pretty. */

.box {
  background: #1D4ED8;
  border-radius: 5px;
}

.container {
  gap: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

span {
  display: inline-block;
  padding: 1rem;
  color: white;
  line-height: 1.45;
  font-size: 1.15rem;
  font-weight: 100;
}

button {
  margin-bottom: 1rem;
}

* {
 font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif; 
}

.description {
  margin-bottom: 2rem;
}
              
            
!

JS

              
                import { up, down, toggle} from "https://cdn.skypack.dev/slide-element@2.1.0";

// down() example
document.getElementById('downButton').addEventListener('click', (e) => {
  down(document.getElementById('downExample')).then(isOpen => {
    e.target.innerText = `It's ${isOpen ? 'open' : 'closed'}!`;
  });
});

// up() example
document.getElementById('upButton').addEventListener('click', (e) => {
  
  // Only here for demo purposes. Not essential to the function of the library.
  document.getElementById('upExample').style.display = "block";
  
  up(document.getElementById('upExample')).then(isOpen => {
    e.target.innerText = `It's ${isOpen ? 'open' : 'closed'}!`;
  });
});

// toggle() example
document.getElementById('toggleButton').addEventListener('click', (e) => {
  toggle(document.getElementById('toggleExample')).then(isOpen => {
    e.target.innerText = `It's ${isOpen ? 'open' : 'closed'}!`;
  });
});
              
            
!
999px

Console