本帖最后由 马黑黑 于 2024-6-28 16:50 编辑
我试了一下另一种JS优化方法,不需要 window.getComputedStyle(ele) 函数,不过设计的依据过于抽象,想想还是这个示例一楼的实现方法牢靠。JS代码如下:
var running = true, idx = 0;
b1.onanimationend = () => {
let ar = ['', 'move1', 'move2', ''];
b1.style.animationName = ar[idx];
idx = (idx +1) % 4;
b2.style.animationName = ar[idx];
};
b2.onanimationend = () => {
let ar = ['', 'move2', '', 'move2'];
b2.style.animationName = ar[idx];
idx = (idx +1) % 4;
b1.style.animationName = ar[idx];
};
b1.onclick = b2.onclick = () => {
stage.style.setProperty('--state', ['running','paused'][+running]);
running = !running;
};
|