Set a CSS3 transition to none

╄→гoц情女王★ 提交于 2019-12-30 00:14:44

问题


How would I make it so a CSS transition doesn't work inside a media-query, or in any other case? For example:

@media (min-width: 200px) {
    element {
        transition: width 1s;
    }   
}

@media (min-width: 600px) {
    element {
        transition: none; // SET TO NO TRANSITION
    }   
}

回答1:


You can set the transition-property to none. This way, no transition effect will be applied.

Like this:

-webkit-transition-property: none;
-moz-transition-property: none;
-o-transition-property: none;
transition-property: none;



回答2:


Even better than setting transition-property to none is setting transition-duration to 0s.

This is the cross-browser code:

-webkit-transition-duration: 0s;
-moz-transition-duration: 0s;
-o-transition-duration: 0s;
transition-duration: 0s;

Why is this better? Because, by default, standards-compliant browsers (such as Firefox) set transition-property to all for each element. They also set transition-duration to 0s. Thus, by setting transition-duration to 0s, you are most closely matching how the browser defines an element without a transition.

Setting the transition-duration to the default 0s renders the transition-property irrelevant.




回答3:


transition: width 0s

Should do the trick - as it's basically saying there is a transition, but 0s is too quick to see it!



来源:https://stackoverflow.com/questions/11848701/set-a-css3-transition-to-none

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!