1 回答

TA貢獻(xiàn)1911條經(jīng)驗(yàn) 獲得超7個(gè)贊
您必須將您的代碼放在<script>的最底部<body>,以便代碼在您的 DOM 加載后起作用。
const move = document.querySelector('#move')
const angle = Math.atan2(document.documentElement.clientHeight, document.documentElement.clientWidth);
const width = document.documentElement.clientWidth / Math.cos(angle);
move.style.setProperty('--a', angle + 'rad');
move.style.setProperty('--w', width + 'px');
html, body, #move {margin:0; padding:0}
#move {
width: 0;
height: 4px;
background: red;
position: relative;
animation: mymove 3s;
animation-fill-mode: forwards;
transform: rotate(var(--a));
transform-origin: top left;
}
@keyframes mymove {
to {
width: var(--w);
background-color: blue;
}
}
<div id="move"></div>
- 1 回答
- 0 關(guān)注
- 111 瀏覽
添加回答
舉報(bào)