I have two images (objects) located next to each other in the middle of the page, and I want them to move towards each other, as if they collide and stop when they are placed next to each.
So, for the object on the right side, I wrote the following code, believing that the object should move from left to right, but the result is far from what I expect. Can this be done by transition? I want one of the objects to start moving on the left side, and the other to start moving on the right and meet in the center, as if they wanted to collide.
.one {
border: 3px solid #73AD21;
position: absolute;
}
.two {
top: 45%;
left: 44%;
}
.left1,
.right2 {
float: left;
}
#axis:hover .move-right {
transform: translate(-350px, 0);
-webkit-transform: translate(-350px, 0);
-o-transform: translate(-350px, 0);
-moz-transform: translate(-350px, 0);
}
.object1 {
position: absolute;
transition: all 2s ease-in;
-webkit-transition: all 2s ease-in;
-moz-transition: all 2s ease-in;
-o-transition: all 2s ease-in;
}
<div id="axis" class="one two">
<img class="object1 left1 move-right" src="http://placehold.it/50x50" />
<img class="object2 right2 move-left" src="http://placehold.it/75x75" />
</div>
Run codeHide result
source
share