Home

Awesome

tinyModal.js

Clean, Fast, Modular and customizable Modal Window controller

What? Another one?

But this one is really flexible. And only 2kb (min). And semantic-oriented (content must be in the document).

tinyModal

Features

Still not convinced? Check out this ↓ complete ↓ comparison ↓ table ↓

tinyModalLightboxFancybox 2Bootstrap's Modal.js
Size2kb ✔8kb23kb8kb
Dependencyjust some CSS ✔jQuery (+88kb)jQuery (+88kb)jQuery (+88kb) + Bootstrap.js (30kb)
Performancesmooth ✔heavy repaintheavy repaintgood
Designyour CSS ✔ownownown
Effectsyour CSS3 ✔ownownown
Responsivesure ✔nopenopeyes
Mobile-friendlyyep ✔nopenopenope
Conflictnone ✔probablyprobablyprobably
Targetcoders ✔newbiesnewbiesnewbies

Demos

tinyModal demo

Use

<aside id="first-modal" class="tinymodal-window">
	<div class="tinymodal-inner">
    	...
    	<button class="tinymodal-close">X</button>
    </div>
</aside>
<a href="#first-modal" class="tinymodal-modal">Open first-modal</a>
var links = document.querySelectorAll('a.tinymodal-modal');

for (var i = 0; links.length > i; i++) {
  links[i].addEventListener("click", function(event){  // callback
    event.preventDefault();
    var element = this.getAttribute("href");
    tinyModal.openModal(element, function(){
      var closeLink = this.querySelectorAll('a[href="javascript:closeModal()"]');
      if (closeLink.length < 1) {
        var closeLink = document.createElement("a");
        closeLink.setAttribute("href","javascript:closeModal()");
        closeLink.innerHTML = "X";
        this.appendChild(closeLink);
      }
    });
  });
}
<button onclick="javascript:openModal();">Open #first-modal with JS</button>
<button onclick="javascript:closeModal();">Close with JS</button>
function openModal() {
    tinyModal.openModal("#first-modal", function(){ 
        // callback
        console.log('#first-modal opened'); 
    });
}

function closeModal() {
    tinyModal.closeModal(function(){  
        // callback
        console.log('closed by closeModal() function');
    });
}

Design

Base modal styles are included in tinyModal.scss but you should add your own styles. Base CSS classes for design are:

.tinymodal-cover    {}
.tinymodal-window   {}
.tinymodal-active   {}
.tinymodal-close    {}

And the functional CSS classes are:

.tinymodal-ready        {}
.tinymodal-active       {}
.tinymodal-window-open  {}
.tinymodal-ready        {}

Developing

Need to change anything?

$ git clone 	https://github.com/juanbrujo/tinyModal.git
$ npm install
$ grunt // build
$ grunt watch // develop
$ grunt testjs // jshint test

Bugs?

tinyModal issues