Last active
September 9, 2015 14:13
-
-
Save daniellizik/bf300e313e60425767f0 to your computer and use it in GitHub Desktop.
flexbox alerts with velocity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var modal = (function(base) { | |
"use strict"; | |
var className = "itemContainer__item"; | |
var containerClassName = "itemContainer"; | |
var containerId = "bmk-itemContainer"; | |
var classSelector = "." + className; | |
var container = elem({ | |
className: containerClassName, | |
id: containerId | |
}); | |
function init(opts) { | |
var instance = new Factory(opts); | |
set(instance.modal); | |
} | |
function Factory(opts) { | |
this.modal = elem(opts); | |
document.getElementById(containerId).appendChild(this.modal); | |
} | |
function elem(opts) { | |
var el = document.createElement("div"); | |
el.className = opts.className || className; | |
if (opts.id) el.id = opts.id; | |
if (opts.text) el.appendChild(document.createTextNode(shorten(opts.text))); | |
return el; | |
} | |
function shorten(str) { | |
return str.length > 50 ? str.substring(0, 50) + " ..." : str; | |
} | |
function set(el) { | |
el.style.display = "initial"; | |
Velocity(el, {opacity: 0}, {delay: 2000, duration: 2000, complete: slice}); | |
} | |
function slice(el) { | |
el[0].parentNode.removeChild(el[0]); | |
} | |
base.appendChild(container); | |
return init; | |
})(document.body); | |
modal({text: "slfjkajfjlfjaklfakjsfsjfsfsf"}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment