<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
#div_1 {
width: 100px;
height: 100px;
transition-property: top;
transition-duration: 1s;
position: absolute;
top: 50px;
background-color: red;
}
.noAnimate {
transition: none;
}
</style>
<script>
function domRedraw_1(dom) {
// 藉著寬度改變
var css = getComputedStyle(dom, null);
var oldStyle = dom.style.cssText;
/* ------------------------ */
/**
* 改變寬度
*
* 寬度+1
*
* 再改回來
*/
var width = css.width.replace(/\D/g, '');
width = Number(width);
width++;
dom.style.width = width + 'px';
/* ------------------------ */
// 回復
dom.style.cssText = oldStyle;
};
function domRedraw_2(dom) {
// 藉著(offsetHeight)
dom.offsetHeight;
};
</script>
<script>
function test_1() {
var div = document.querySelector('#div_1');
var style = div.style;
style.removeProperty('display');
// important
domRedraw_1(div);
style.top = '200px';
}
</script>
</head>
<body>
<button onclick="test_1();">Click!</button>
<div id="div_1" style="display: none">
target
</div>
</body>
</html>