Chose from wide variety of iconic animations and build any kind of
notification popups, off-the-screen forms, beautiful nav bars and much more!
Note that some browsers and OS environment may complain that modal.js is a potential risk to your computer
and they say so because modal.js
is generated on client-side and publisher (me) is not verified on client side.
So you can download and use only if you trust the source and meanwhile can read the content of modal.js
yourself.
modal.js
file, include this JavaScript file at the bottom of HTML content, as shown below.
<body>
...
<h1>I love modal.js</h1>
...
</body>
<script src="./modal.js"></script>
openModal()
function to open the modal window.openModal()
function, let's trigger it using a button.
<body>
...
<button> onclick="openModal()">Click to open modal</button>
<h1>I love modal.js</h1>
...
</body>
<script src="./modal.js"></script>
That's it! Your modal window should work like a breeze now.
Now, theres an interesting but common case, you've downloaded the modal.js
file, but after downloading
the file, you've found to modify either the HTML being rendered inside the modal or the style of modal itself.
modal.js
file that you've downloaded.document.body.innerHTML
in modal.js file.
...
//HTML inside the modal and Input CSS animation tag
document.body.innerHTML +=
`<div class="modal" id="myModal">
<div class="modal-content-area animated shake">
<i class="close-button" aria-hidden="true">✖</i>
<h1>Hello world</h1>
<p>It's shahzaib here.</p>
<p>Download resume</p>
</div>
</div>`;
//Output CSS animation name
classesToHide = ['modal-content-area', 'animated', 'wobble'];
//Input CSS animation tag
classesToRetainOriginal = ['modal-content-area', 'animated', 'shake'];
...
shake
is input animation, while wobble
is output animation.modal.js
file to change animations and HTML content of modal window.Now, after HTML content and animations, next thing to modify is CSS styling of modal window and the HTML content within modal window.
modal.js
file.$modalCSS
first occurance in file.
...
$outputAnimation: 'wobble',
$modalCSS: `.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.4);
overflow:auto;
}
...
That's it. Now, you can add or remove CSS style tags here and thus modify modal window styling.
That's complicated! But there's a workaround.
modal.js
file.openModal()
with something like openModalSecond()
..modal
with .modalSecond
.modal.js is written by Shahzaib Khalid
modal.js is being maintained on GitHub
modal.js is licensed under the MIT License.
Copyright (c) 2017 Shahzaib Khalid