在浏览器调整大小时触发 CSS3 转换

发布于 2025-01-04 00:14:41 字数 343 浏览 1 评论 0原文

我一直在玩动画 CSS3 媒体查询,是的,我知道它们的实际用途值得怀疑,但它很有趣。无论如何,我可以将 box/divs/selectors 获取到 transition/expand/contract 等浏览器调整大小,但我在转换时遇到问题。我想做的是以特定分辨率翻转或旋转 div。

可以将其视为 iPad 从横向变为纵向以及发生这种情况时 div 翻转。

这实际上可能吗?如果是的话,我错过了什么/做错了什么?

I have been playing with animated CSS3 Media Queries, yes I know their practical use is questionable but it is fun. Anyways, I can get boxes/divs/selectors to transition/expand/contract etc on browser resize but I am having problems with transforms. What I am trying to do is make a div flip or rotate at certain resolutions.

Think of it as an iPad changing from landscape to portrait and a div flipping when this happens.

Is this actually possible and if so what am I missing/doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半衾梦 2025-01-11 00:14:41

好的,我现在可以使用了。基于后伊拉斯谟的 CSS,我能够对其进行调整并使其 100% 工作。代码如下:

 .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;

    }   
}

当然,您需要添加其他供应商特定的前缀。当您为属性设置动画时,您需要指定开始和结束状态。因此,忽略变换似乎会将属性重置为 0。

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.

薄凉少年不暖心 2025-01-11 00:14:41

您是否尝试过使用媒体查询?

.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;
        }
}

通过对 ie、firefox 等进行适当的(附加)转换,它似乎可以工作。

我在这里组装了一个jsfiddle。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文