【问题标题】:CSS transition only one transform functionCSS 过渡只有一个变换函数
【发布时间】:2014-03-20 22:44:54
【问题描述】:

有没有办法只为一个变换函数设置动画?例如,我只想要我的比例功能转换。我将如何做到这一点

.my-class {
    transition: transform;
}
.large {
    transform: scale(2) rotate(90deg);
}

<div class="my-class"></div>
<div class="my-class large"></div>

【问题讨论】:

  • 正是你所做的。 (加上供应商前缀和过渡时间)什么不起作用?
  • @bjb568 我真正想要的不是在我的转换中包含旋转,因为他在转换属性上。我的目标是只有变换属性上的缩放功能才会动画。帮助
  • 哦,那我不知道该怎么做。
  • 你想只转换类 .large 吗?
  • @Prasanth 是的。但只有比例会动画

标签: html css transform transition


【解决方案1】:

我玩过你的代码,是的,你可以。只需将不同的转换函数分配给不同的类,然后只使用您想要的那些类……就像这样。

重要的是DO NOT FORGET 在使用动画使其工作时使用相应的browser supported engines。以下是支持各种动画功能的各种浏览器的列表。

http://css3.bradshawenterprises.com/support/

.my-class {
    transition: transform;
}

.scale_and_rotate {
    -webkit-transform: scale(2) rotate(90deg);
    -moz-transform: scale(2) rotate(90deg);
    -ms-transform: scale(2) rotate(90deg);
    -o-transform: scale(2) rotate(90deg);    
}

.scale_class {
    -webkit-transform: scale(2); // Safari and Chrome(Engine:-Webkit)
    -moz-transform: scale(2); // Mozilla(Engine:-Gecko)
    -ms-transform: scale(2); // IE(Engine:-Trident)
    -o-transform: scale(2); // Opera(Engine:-Presto)
}


.rotate_class {
    -webkit-transform: rotate(90deg);
    -moz-transform: rotate(90deg);
    -ms-transform: rotate(90deg);
    -o-transform: rotate(90deg);
}

最后,您可以根据自己的要求应用这些课程

<div class="my-class"></div>
<div class="my-class scale_class"></div> // only scale function
<div class="my-class rotate_class"></div> // only rotate function
<div class="my-class scale_and_rotate"></div> // both scale and rotate function

查看JSFiddle here

如果你想一起缩放和旋转,那么你给出的类应该可以工作。 你也可以查看 CSS @keyframes 来实现这一点。这里有一些很好的教程

https://developer.mozilla.org/en-US/docs/Web/CSS/@keyframes

http://coding.smashingmagazine.com/2011/05/17/an-introduction-to-css3-keyframe-animations/

【讨论】:

  • 您是否在浏览器上尝试过此代码?我认为“缩放和旋转” div 是:rotate_class 只会覆盖 scale_class 的变换属性。 scale 函数将不会被执行,因为它被 rotate 函数覆盖。对不起,我知道我无法解释,但我希望你明白我的意思
  • 哎呀,我忘了添加一个类。已编辑更改只需检查 fiddle 以获取完整代码
  • 对不起,我也忘记将转换值设置为 [transform 2s],再次抱歉,因为我没有具体解释我想要什么。现在我的主要观点是,例如我有一个没有类的 div,并且我有一个脚本可以在其上放置一个类(scale_and_rotate)然后我只希望在缩放函数上进行 2 秒的过渡变换,旋转时不会有动画跨度>
  • 好的,那么您现在可以相应地更新问题,以便其他人也可以帮助您
  • 你也可以创建一个小提琴来更好地解释你的问题
猜你喜欢
  • 1970-01-01
  • 2018-09-09
  • 1970-01-01
  • 2020-02-09
  • 1970-01-01
  • 2014-10-04
  • 2021-02-14
  • 2015-11-16
  • 1970-01-01
相关资源
最近更新 更多