The problem I has with this question was that when expanding a div that is positioned in the middle of a div would then make the element out of center. What makes this different from other question was that I couldn't specificity the width and height of the div. Therefore I needed a solution.
I now have the solution, thanks for the help!
I've included code to help explain the problem I am having.
var elem = document.getElementById("one");
var onload = function() {
elem.style.left = "calc(50% - 40px)";
elem.style.top = "calc(50% - 40px)";
}
onload();
var expand = document.getElementById("expand");
var reset = document.getElementById("reset");
expand.addEventListener("click", function () {
elem.style.width = "200px";
elem.style.height = "200px";
});
reset.addEventListener("click", function () {
elem.style.width = "80px";
elem.style.height = "80px";
});
#one {
width: 80px;
height: 80px;
background-color: red;
position: absolute;
border-radius: 50%;
transition: all 2s;
}
<div id="one"></div>
<button id="expand">click</button>
<button id="reset">reset</button>