Triggering CSS3 Transform on browser resize

安稳与你 提交于 2019-12-05 17:48:35

Ok, I have it working now. Based on post-erasmus' css I was able to tweak it and get it working 100%. Here's the code:

 .test{width: 400px; height: 200px; 
 -webkit-transform: rotate(0deg);
transition:all .2s linear;
-o-transition:all .2s linear;
-moz-transition:all .2s linear;
-webkit-transition:all .2s linear;
-webkit-transform-style: preserve-3d;
}

@media screen and (max-width: 319px){
    .test{
            background-color: orange;
            -moz-transform: rotate(360deg);
            -webkit-transform: rotate(360deg); 
    }
}

@media screen and (min-width: 320px) and (max-width: 700px){
    .test{
            background-color: green; 

    }
}
@media screen and (min-width: 701px) and (max-width: 1200px){
    .test{
            background-color: red; 
            -moz-transform: rotate(360deg);
            -webkit-transform: rotate(360deg); 

    }
}

@media screen and (min-width: 1201px){
    .test{
            background-color: blue;

    }   
}

Of course, you need to add the other vendor specific prefixes. When you animate a property, you need to specify both the beginning and ending state. So it seems that leaving out the transform will reset the property to 0.

Have you tried using media queries?

.test{
        background-color: blue; 
        -webkit-transform: rotate(360deg); 
        -moz-transform: rotate(360deg);
        -ie-transform: rotate(360deg);
        transform: rotate(360deg);
        margin: -26px -26px -26px -26px;
}
@media screen and (min-width: 320px) and (max-width: 700px){
        .test{
                background-color: green; 
                -webkit-transform: rotate(360deg); 
                -moz-transform: rotate(360deg);
                -ie-transform: rotate(360deg);
                transform: rotate(360deg);
                margin: -26px -26px -26px -26px;
        }
}
@media screen and (min-width: 700px) and (max-width: 1200px){
        .test{
                background-color: red; 
                -webkit-transform: rotate(360deg); 
                -moz-transform: rotate(360deg);
                -ie-transform: rotate(360deg);
                transform: rotate(360deg);
                margin: -26px -26px -26px -26px;
        }
}

With the appropriate (additional) transforms for ie, firefox, etc. It appears to work.

I put together a jsfiddle here.

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