This file contains hidden or 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
#container{ | |
position: absolute; | |
margin:auto; | |
width: 1000px; | |
height: 1123px; | |
} | |
#body{ | |
position:absolute; | |
width:794px; /* width of actual image */ |
This file contains hidden or 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
function next(item){ | |
let next_num = dressupState[item].current + 1 | |
// if next_num exceeds total, restart (set current to 0) | |
let new_current = next_num < dressupState[item].total ? next_num : 0 | |
updateDressUp(item, new_current) | |
} | |
function updateDressUp(item,new_current){ | |
setDressupState({ | |
...dressupState, |
This file contains hidden or 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
function randomize(){ | |
// for each dressup item, generate a random integer and assign it to current | |
Object.keys(dressupState).map((item) => | |
updateDressUp(item, Math.floor(Math.random() * Math.floor(dressupState[item].total))) | |
) | |
} |
This file contains hidden or 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
import './assets/scss/style.scss'; | |
import React, { useState } from 'react'; | |
function App() { | |
// ATM you need to manually add new items and update the total values per item | |
const [dressupState, setDressupState] = useState({ | |
eyes: {current: 0, total: 9}, | |
ears: {current: 0, total: 3}, | |
mouth: {current: 0, total: 4}, |
This file contains hidden or 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
// dressupState was defined earlier | |
<div id="container"> | |
<div id="background"> | |
<div id="body"></div> | |
{ Object.keys(dressupState).map((item) => | |
<div id={item} className={item+(dressupState[item].current+1)} key={item}></div> | |
) | |
} | |
</div> |
This file contains hidden or 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
<div id="container"> | |
<div id="background"> | |
<div id="body"></div> | |
<div id="eyes" className={"eyes"+(dressupState["eyes"].current+1)} ></div> | |
<div id="ears" className={"ears"+(dressupState["ears"].current+1)}></div> | |
<div id="nose" className={"nose"+(dressupState["nose"].current+1)}></div> | |
<div id="mouth" className={"mouth"+(dressupState["mouth"].current+1)}></div> | |
<div id="clothes" className={"clothes"+(dressupState["clothes"].current+1)}></div> | |
</div> | |
</div> |
NewerOlder