CSS3 2D 3D 过度与动画

2D

使用transform属性,结合2D变换方法

下面代码是基本模板

div
{
    transform:rotate(7deg);
    -ms-transform:rotate(7deg); /* IE 9 */
    -webkit-transform:rotate(7deg); /* Safari and Chrome */
}
<body>
    <div class="contain">
        <div class="test">我是新的位置</div>
        <div class="test2">我是老的的位置</div>
    </div>
</body>
body {
    padding: 10px;
}

.contain {
    border: 1px solid;
    height: 500px;
    padding: 50px;
    position: relative;
}
.test{
    width: 300px;
    line-height: 300px;
    background-color: crimson;
    text-align: center;
    transform: translate(220px,50px);
}
.test2{
    width: 300px;
    line-height: 300px;
    text-align: center;
    background: yellow;
    position: absolute;
    top: 50px;
    z-index: -1;
}

转换方法:

transform: translate(220px,50px);

translate(x,y)  偏移距离基于左上角,x轴,y轴 ,因为是基于点的位置,也可以认为原点是元素中心

transform: rotate(60deg);

rotate()以元素中心旋转,正数顺时针旋转

transform: scale(0.5,0.5);

scale(x,y)  中心位置不变,宽高变为对应的倍数

transform: skew(30deg,30deg);

scale(x,y),以中心位置建立直角坐标系,倾斜角度,分别是宽和高与x轴和y轴的角度

x角度表示高与x轴的角度,y角度表示宽与y轴的角度

transform-origin:50% 50%;

以元素原始位置的左上角为基准点,改变2D转换的基准位置,50%恰好是元素的中心位置

3D

transform: rotateX(45deg);

围绕x轴旋转角度

其他变换参考这个标准来就行

transform-style: flat|preserve-3d

描述
flat表示所有子元素在2D平面呈现。
preserve-3d表示所有子元素在3D空间中呈现。

过度

transition: width 2s

transition: all 2s;过度效果必须有类是hover这样得事件去定义元素终态

动画

@keyframes mymove //定义动画效果
{
0%   {top:0px; left:0px; background:red;}
25%  {top:0px; left:100px; background:blue;}
50%  {top:100px; left:100px; background:yellow;}
75%  {top:100px; left:0px; background:green;}
100% {top:0px; left:0px; background:red;}
}

@-webkit-keyframes mymove /* Safari and Chrome */
{
0%   {top:0px; left:0px; background:red;}
25%  {top:0px; left:100px; background:blue;}
50%  {top:100px; left:100px; background:yellow;}
75%  {top:100px; left:0px; background:green;}
100% {top:0px; left:0px; background:red;}
}

div
{
    animation:mymove 5s infinite;//执行动画并定义不服动画属性
    -webkit-animation:mymove 5s infinite; /* Safari 和 Chrome */
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Box2D和Cocos2D是两个游戏开发框架。Box2D是一个用于物理模拟的开源库,可以模拟刚体的运动和碰撞等物理效果。Cocos2D是一个用于2D游戏开发的跨平台框架,提供了丰富的图形渲染和用户交互功能。\[1\] 在使用Cocos2D和Box2D进行游戏开发时,你可以利用Box2D来处理游戏中的物理效果,比如重力、碰撞和刚体运动等。Cocos2D提供了与Box2D的集成,使得开发者可以方便地在Cocos2D中使用Box2D的功能。你可以通过创建物理世界、添加刚体和设置碰撞检测等来实现游戏中的物理效果。\[2\] 如果你刚刚接触Cocos2D和Box2D,建议你先学习Cocos2D和Box2D的基础知识,然后再深入学习如何在Cocos2D中使用Box2D。你可以参考一些入门教程,比如《Cocos2D入门》和《Box2D入门》。如果你对OpenGL ES 2.0和自定义Cocos2D 2.X着色器等背景知识感到困惑,你可以查阅相关教程来获取更多的帮助。\[3\] #### 引用[.reference_title] - *1* *3* [如何使用Box2D和Cocos2D制作一款像Fruit Ninja一样的游戏-第1部分](https://blog.csdn.net/kaka626/article/details/9397825)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [用Box2D和cocos2d-x制作弹弓类游戏](https://blog.csdn.net/qq55008307/article/details/8090839)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值