Disable/turn off inherited CSS3 transitions

前端 未结 5 1931
我寻月下人不归
我寻月下人不归 2020-12-23 08:39

So i have the following css transitions attached to the a element:

a { 
     -webkit-transition:color 0.1s ease-in, background-color 0.1s ease-in ;  
     -m         


        
5条回答
  •  南笙
    南笙 (楼主)
    2020-12-23 09:16

    The use of transition: none seems to be supported (with a specific adjustment for Opera) given the following HTML:

    Content
    Content
    Content
    Content
    

    ...and CSS:

    a {
        color: #f90;
        -webkit-transition:color 0.8s ease-in, background-color 0.1s ease-in ;  
        -moz-transition:color 0.8s ease-in, background-color 0.1s ease-in;  
        -o-transition:color 0.8s ease-in, background-color 0.1s ease-in;  
        transition:color 0.8s ease-in, background-color 0.1s ease-in; 
    }
    a:hover {
        color: #f00;
        -webkit-transition:color 0.8s ease-in, background-color 0.1s ease-in ;  
        -moz-transition:color 0.8s ease-in, background-color 0.1s ease-in;  
        -o-transition:color 0.8s ease-in, background-color 0.1s ease-in;  
        transition:color 0.8s ease-in, background-color 0.1s ease-in; 
    }
    a.noTransition {
        -moz-transition: none;
        -webkit-transition: none;
        -o-transition: color 0 ease-in;
        transition: none;
    }
    

    JS Fiddle demo.

    Tested with Chromium 12, Opera 11.x and Firefox 5 on Ubuntu 11.04.

    The specific adaptation to Opera is the use of -o-transition: color 0 ease-in; which targets the same property as specified in the other transition rules, but sets the transition time to 0, which effectively prevents the transition from being noticeable. The use of the a.noTransition selector is simply to provide a specific selector for the elements without transitions.


    Edited to note that @Frédéric Hamidi's answer, using all (for Opera, at least) is far more concise than listing out each individual property-name that you don't want to have transition.

    Updated JS Fiddle demo, showing the use of all in Opera: -o-transition: all 0 none, following self-deletion of @Frédéric's answer.

提交回复
热议问题