gpt4 book ai didi

html - 当多个运行时,是否可以检测到最后一个 CSS 转换的结束?

转载 作者:行者123 更新时间:2023-11-28 04:33:00 27 4
gpt4 key购买 nike

如果一个元素的多个 css 属性发生变化并且它们具有不同的过渡持续时间,是否有一种方法可以检测到最后一个/最长运行过渡的完成。

例子:

<style>
.box {
width: 100px;
height: 100px;
transition: width 0.5s, height 6s;
}

.animate {
width: 400px;
height: 400px;
}
</style>

<div class="box"></div>

<script>

// I want to run some code after both the width and height transitions
// are complete

// Listening for transitionend events will fire on every transition
// that ends. So in this case, both width and height. Assume I don't
// know how many properties are being transitioned.
$('.box').on('transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd', function(ev) {
// ...
});
$('.box').addClass('animate');

</script>

最佳答案

你可以找出转换的次数,然后倒数。

var box = document.getElementsByClassName('box')[0];
numTransitions = getComputedStyle(box).transition.split(',').length;

如果你的 CSS 不干净,那会有点脆弱,但也许你可以控制它

关于html - 当多个运行时,是否可以检测到最后一个 CSS 转换的结束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41644098/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com