- [Instructor] While we're here,…let's create our stacking function…and attach it to our deck.…So back in our main.js,…we'll call a this.stack function,…we'll pass in the deck_div…because we'll use that to get the card elements.…Let's create the stack function…by coming down here after the shuffle,…and we'll do again a Deck.prototype,…and this one's going to be called stack equals function,…and again let's pass through that deck_div.…
The first thing we want to do is get the cards,…so I'll say var cards equals deck_div.children,…and whereas the deck_div is the container,…children gets all of the divs inside of the deck_div.…So let's loop through those with a for loop.…And for each card,…we want to move it to the right and down one pixel.…So for that we'll use style.top equals i…plus px for pixels,…and again cards with the index i,…style.left equals i plus pixel.…
Finally, let's add a class,…and we'll say cards at index i…is a class list,…and let's add a class of stacked_card.…Typically I don't modify the style attribute.…
- Working with prototype and dynamic elements
- Using bind, call, and apply
- Using the Fisher–Yates formula
- When to use e.preventDefault() and when to avoid it
- Drag-and-drop life cycle
- Using prototypical inheritance to optimize your code
Skill Level Intermediate
Q: This course was updated on 1/16/2019. What changed?
A: The following topics were updated: propagation and drag and drop.