Minimal Modal Window JavaScript Class

Category: Javascript , Modal & Popup | September 28, 2021
Author:enamul-hoque
Views Total:50 views
Official Page:Go to website
Last Update:September 28, 2021
License:MIT

Preview:

Minimal Modal Window JavaScript Class

Description:

A JavaScript library that exposes a class to create modal windows with ease.

How to use it:

1. Add your content together with a close icon to the modal window.

<div id="messageBox">
  <i class="close">x</i>
  <p>Modal Content Here</p>
</div>

2. Create a button to toggle the modal window.

<button type="button" data-modal="messageBox">Open Modal</button>

3. Load the main JavaScript modal.js at the end of the document.

<script src="assets/js/modal.js"></script>

4. Hide the modal window on init.

#messageBox {
  display: none;
}

5. Style the modal window.

#messageBox.active {
  display: block;
  position: fixed;
  top: 50%;
  left: 50%;
  right: 0;
  max-width: 480px;
  padding: 0 20px;
  background-color: #fff;
  box-shadow: 0 5px 15px rgb(0 0 0 / 15%);
  transform: translate(-50%);
  z-index: 999;
}

6. Style the close icon.

.close {
  position: absolute;
  top: -15px;
  right: -15px;
  width: 30px;
  height: 30px;
  background-color: #fff;
  box-shadow: 0 5px 8px rgb(0 0 0 / 15%);
  border-radius: 50%;
  text-align: center;
  font-size: 18px;
  line-height: 30px;
  font-family: Arial;
  font-style: normal;
  cursor: pointer;
}

You Might Be Interested In:


Leave a Reply