Avoid setting elem.style.top = "NaNpx"