So basically i wanted to create a kind of door effect with a div
Open and Shut when clicking a button.
var buttons = document.querySelectorAll('button');
[].forEach.call(buttons, function(btn) {
btn.addEventListener('click', function(e) {
var target = e.target;
if (target.nodeName.toLowerCase() === 'button') {
document.getElementById(target.dataset.target + '-div').className = target.textContent === 'stop' ? '' : target.textContent;
}
});
});
button {
height: 24px;
font-size: 16px;
}
div {
position: relative;
left: 0;
margin-left: 0;
padding-left: 0;
transform: none;
margin-top: 10px;
width: 200px;
height: 200px;
border: 0 white solid;
background-color: green;
}
#transition-div {
transition: transform 1s ease-in-out;
}
#transition-div.start {
transform: translateX(400px);
}
@keyframes move-right {
0% { transform: translateX(0px); }
50% { transform: translateX(400px); }
100% { transform: translateX(0px); }
}
<section>
<h1>Transition</h1>
<button data-target="transition">start</button>
<button data-target="transition">stop</button>
<div id="transition-div"></div>
</section>
Can the top result be created in pure CSS or does javascript have to be implemented into the webpage? And are you able to have a 'start' and 'stop' button merged into one single button? Cheers guys!