Basic Modal Popup with Vanilla JavaScript and HTML5 – Modalzinha.js

Category: Javascript , Modal & Popup | October 15, 2015
Author: ferspeak
Views Total: 4,316 views
Official Page: Go to website
Last Update: October 15, 2015
License: MIT

Preview:

Basic Modal Popup with Vanilla JavaScript and HTML5 – Modalzinha.js

Description:

Modalzinha.js is an extremely lightweight vanilla JavaScript plugin used to display a simple, dismissable modal popup using plain html.

Basic usage:

Load the JavaScript file modalzinha.js at the end of the document.

<script src="modalzinha.js"></script>

Create the modal content following the html structure like this:

<div class="modal-wrapper" data-modal="wrapper">
  <div class="modal-content">
    <button data-modal="close">&times;</button>
    Modal Content
  </div>
</div>

Create a trigger button with the data-modal="open" attribute.

<button data-modal="open">Lanuch</button>

Style the modal popup in the CSS.

.modal-wrapper {
  width: 100%;
  height: 100%;
  min-height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background-color: rgba(0,0,0,.7);
  transition: .4s;
  visibility: hidden;
  opacity: 0;
  z-index: 100;
}

.modal-content {
  max-width: 400px;
  width: 100%;
  position: absolute;
  top: 30%;
  left: 0;
  right: 0;
  margin: 0 auto;
  z-index: 10;
  background-color: #1ABC9C;
  border-radius: 5px;
  color: #fff;
}

.modal-opened {
  opacity: 1;
  visibility: visible;
}

You Might Be Interested In:


Leave a Reply