简体   繁体   English

CSS transition-duration不会更新转换?

[英]CSS transition-duration does not update the transition?

I am currently writing a jQuery plugin to create / manage CSS transitions, and I found this strange behavior with transition-duration. 我目前正在编写一个jQuery插件来创建/管理CSS转换,我发现这个奇怪的行为有转换持续时间。

Apparently, while a transition is running, any changes to the duration property are ignored unless the properties being transitioned receive a different value. 显然,在转换正在运行时,将忽略对duration属性的任何更改,除非正在转换的属性接收不同的值。 The duration itself does not cause the transition to change. 持续时间本身不会导致转换发生变化。

Following is some code which shows an example of this, and below are some links to jsFiddle to give you a better idea of the transition behavior I am trying to achieve. 下面是一些显示此示例的代码,下面是jsFiddle的一些链接,可以让您更好地了解我想要实现的转换行为。

    /* starting transition */
    .t1 {
        -webkit-transition-duration: 5s;
        -webkit-transition-property: width;
        width: 500px;
    }

    /* during the above, this will do nothing */
    .t2 {
        -webkit-transition-duration: 200ms;
        -webkit-transition-property: width;
        width: 500px;
    }

    /* but this will override the transition as expected */
    .t3 {
        -webkit-transition-duration: 200ms;
        -webkit-transition-property: width;
        width: 501px; /* 1 pixel added */
    }

Any ideas on how to force the transition to accept the updated duration? 有关如何强制过渡以接受更新持续时间的任何想法?

UPDATE UPDATE

It looks like this behavior is defined in the spec, but I am still open to a workaround if anyone has one. 看起来这个行为是在规范中定义的,但如果有人有一个,我仍然可以解决这个问题。

(From www.w3.org/TR/css3-transitions/#starting) (来自www.w3.org/TR/css3-transitions/#starting)

Once the transition of a property has started, it must continue running based on the original timing function, duration, and delay, even if the 'transition-timing-function', 'transition-duration', or 'transition-delay' property changes before the transition is complete. 一旦属性的转换开始,它必须基于原始的定时功能,持续时间和延迟继续运行,即使“转换 - 定时 - 功能”,“转换持续时间”或“转换延迟”属性发生更改转换完成之前。

I've run into the same issue when I needed to overwrite transition-duration but leaving the transition-property intact. 当我需要覆盖transition-duration但保持transition-property完好无损时,我遇到了同样的问题。 The only simple workaround I've found so far is to actually change transition-property a little bit, ie instead of opacity: 0 make it opacity: 0.0001 . 到目前为止,我发现的唯一简单的解决方法是实际更改transition属性,即代替opacity: 0使其opacity: 0.0001

刚测试了Chrome和Safari的第一个链接,它运行正常,就像jQuery示例:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM