Indeed, achieving the desired effect requires separate transformations for the body of the shape (similar to a rectangle) and the two circles.
$(document).ready(() => {
$('button').click(() => {
$('.shape').toggleClass('expanded');
});
});
.shape {
position: relative;
margin-left: 200px;
}
.circle {
position: absolute;
top: 0;
left: -12px;
background: red;
width: 24px;
height: 24px;
border-radius: 24px;
background: blue;
transition: transform .5s;
}
.rect {
width: 1px;
height: 24px;
background: blue;
transition: transform .5s;
}
.shape.expanded .circle.left {
transform: translateX(-32px);
}
.shape.expanded .circle.right {
transform: translateX(32px);
}
.shape.expanded .rect {
transform: scaleX(64);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="shape">
<div class="circle left"></div>
<div class="rect"></div>
<div class="circle right"></div>
</div>
<button>toggle</button>