1 var StackCards = function(parent) {2 this.dom = parent;3 this.stack = ([]);4 5 this.dom.setAttribute('b', 'StackCards');6 }7 8 StackCards.prototype.push = function(card) {9 card.setAttribute('b', 'Card');10 card.classList.add('Card-out');11 this.stack.push(card);12 13 this.dom.appendChild(card);14 card.offsetTop;15 16 card.addEventListener('animationstart', function(e){alert('ya!');}, true);17 18 card.classList.remove('Card-out');19 }20 21 StackCards.prototype.pop = function() {22 var card = this.stack.pop();23 this.dom.removeChild(card);24 return card;25 }26 27 28 ////////////////////////////////////////////////////////////7729 30 var TestCard = function(n) {31 var dom = document.createElement('div');32 dom.innerHTML = 'THIS IS A CARD ('+n+')';33 return dom;34 }35 36 ////////////////////////////////////////////////////////////////37 38 var ms; //main stack39 40 window.addEventListener('load', function() {41 ms = new StackCards(document.body);42 43 var c1 = new TestCard('principal');44 c1.addEventListener('click', function(event){45 var c2 = new TestCard('secundaria');46 ms.push(c2);47 }, true);48 ms.push(c1);49 }, true);
Enlace
El enlace para compartir es: