I want to make elements that are placed together explode out from each other by increasing the margin on each of them with a CSS animation. The problem I have is that they end up pushing against the left of the container instead of going outside it, and they end up getting stacked on top of each other. Is there any way to just make them expand outwards? You can see what I've done so far in this example.
function ct(tag, id, attrs) {
var e = document.createElement(tag)
if (typeof id == 'object') attrs=id
if (typeof id == 'string') e.setAttribute('id', id)
for (var a in attrs)
if (attrs[a] !== undefined)
e.setAttribute(a, attrs[a])
return e
}
for (var i = 0; i < 3; i++) {
$('#page').append(ct('div', {'class': 'row_'}))
for (var y = 0; y < 3; y++) {
$('.row_').eq(i).append(ct('div', {'class': 'abc'}))
}
}
$('#start').click(function() {
$('.abc').addClass('move')
})
#page {
height: 160px;
width: 200px;
background: lightgrey;
display: flex;
flex-flow: column;
justify-content: center;
}
.abc {
margin: 1px;
padding: 10px;
background: black;
width: 30px;
display: inline-block;
}
.move {
animation: move 0.6s cubic-bezier(1, 0, 1, 1);
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
@keyframes move {
from {
margin: 1px;
}
to {
margin: 10px;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>
<body>
<div id=page>
</div>
<button id=start>
Start
</button>
</body>
</html>