css3动画实例教程(css3视频教程)

http://www.itjxue.com  2023-01-26 10:50  来源:未知  点击次数: 

如何用CSS3做过渡效果(transition)与动画(animation)麻烦告诉我

div.trans { width:100px; height:100px; background:gray; transition:width 2s; -moz-transition:width 2s; /* Firefox 4 */ -webkit-transition:width 2s; /* Safari and Chrome */ -o-transition:width 2s; /* Opera */ } div.trans:hover { width:300px; } div.ani { width:100px; height:100px; background:red; position:relative; animation:mymove 5s infinite; -moz-animation:mymove 5s infinite; /*Firefox*/ -webkit-animation:mymove 5s infinite; /*Safari and Chrome*/ } @keyframes mymove { from {left:0px;} to {left:200px;} } @-moz-keyframes mymove /*Firefox*/ { from {left:0px;} to {left:200px;} } @-webkit-keyframes mymove /*Safari and Chrome*/ { from {left:0px;} to {left:200px;} }刚开始W3C CSS Workgroup拒绝将CSS3 transition与animation加入官方标准,一些成员认为过渡效果和动画并非样式属性,而且已经可以用脚本实现。语法:transition: property duration timing-function delay;说明:ValueDescriptiontransition-property指定要改变CSS属性的名称transition-duration指定过渡效果要花多少时间(s/ms)transition-timing-function指定过渡效果的速度transition-delay定义过渡效果的延迟时间.实例:style type="text/css" div { width:100px; height:100px; background:red; transition:width 2s; -moz-transition:width 2s; /* Firefox 4 */ -webkit-transition:width 2s; /* Safari and Chrome */ -o-transition:width 2s; /* Opera */ } div:hover { width:300px; } /style div/div 2. AnimationCSS动画(Animations)简单说就是在一段固定的动画时间内暗中在某一频率内改变其CSS某个或某些值,从而达到视觉上的转换动画效果。下面看下一个简单的实例:style type="text/css" div { width:100px; height:100px; background:red; position:relative; animation:mymove 5s infinite; -moz-animation:mymove 5s infinite; /*Firefox*/ -webkit-animation:mymove 5s infinite; /*Safari and Chrome*/ } @keyframes mymove { from {left:0px;} to {left:200px;} } @-moz-keyframes mymove /*Firefox*/ { from {left:0px;} to {left:200px;} }@-webkit-keyframes mymove /*Safari and Chrome*/ { from {left:0px;} to {left:200px;} } /style div/div 语法:animation: name duration timing-function delay iteration-count direction;说明:ValueDescriptionanimation-name指定动画帧的名称animation-duration指定动画运行的时间:秒(s)和毫秒(ms)animation-timing-function指定动画运行的速度animation-delay指定动画的延迟时间animation-iteration-count指定动画的重复数animation-direction指定动画是否以相反的方向运行动画

css3圆环旋转效果动画怎么做

1、首先新建一个html空白文档,取名字叫做css3动画,保存一下。

2、然后写html结构,只需要一个div元素即可,class名字叫做img

3、设置其边框为不同的颜色,边框宽度设置成100px。

4、因为是圆环,所以我们用到了css3的圆角效果,设置圆角为50%,也就是border-radius:50%,看一下效果。

5、接下来就是关键的步骤了,也就是添加动画效果。输入以下代码

6、来看一下最后的效果,还是不错的。

小程序如何使用css3动画

1、利用样式实现小程序动画(用法和css用法相识)

wxml 文件

image class="aniamtion" src="../../images/page4.jfif" style="width:200rpx;height:200rpx;? position:? relative;"/image

wxss文件

.aniamtion {

animation: mymove 5s infinite;

/* //infinite属性是表示无限循环的意思,没有这个属性的话动画只执行一次。 */

}

@keyframes mymove {

from {

? /* left: 0px; */

/* transform: rotate(7deg) skew(50deg) translate(30rpx,30rpx); */

transform: rotate3d(100,200,300,0deg);

}

to {

?/* left: 200px; */

/* transform: rotate(7deg) skew(5deg) translate(100rpx,100rpx); */

transform: rotate3d(200,300,400,360deg);

}

}

2、 用小程序的API来实现动画

用wx.createAnimation(object) 来创建一个动画 --返回一个animation对象

创建一个动画实例 animation。

onReady: function () {

this.animation = wx.createAnimation({

duration:1000,

timingFunction:'linear',

delay:100,

transformOrigin:"left top 0"

})

},

调用实例的方法来描述动画。

Animation.step() 表示一组动画的完成,可以在一组动画中调用任意多个动画方法,一组动画中的所有动画会同时开始,一组动画完成后才会进行下一组动画

rotate(){

this.animation.rotate(150).step() //对动画进行简单的描述

this.setData({

? ? ? ? ?animation:this.animation.export()

})

},

最后通过动画实例的 export 方法导出动画数据传递给组件的 animation 属性。

this.animation.export() 导出动画队列。export 方法每次调用后会清掉之前的动画操作

rotate(){

this.animation.rotate(150).step() //对动画进行简单的描述

this.setData({ // 在setData({}) 导出动画数据数据给组件

? ? ? ? ?animation:this.animation.export()

})

},

完整的wxml

view class="container"

view animation="{{animation}}" class="view"

将做动画的块

/view

/view

button type="default" size="mini" bindtap="rotate"

旋转

/button

完整的wxjs

Page({

data: {

animation:''

},

onReady: function () {

this.animation = wx.createAnimation({

duration:1000,

timingFunction:'linear',

delay:100,

transformOrigin:"left top 0"

})

},

rotate(){

this.animation.rotate(150).step().translate(100).step()

this.setData({

animation:this.animation.export()

})

}

})

3、用选择器来绑定组件来来实现组件的动画(小程序2.9.0 的库可用,版本不够会报this.animate不是一个方法)

textpages/index7/index7.wxml/text

view id="container" style="height: 100px; width: 100px; background-color: blue;"

container

/view

view class="block" style="height: 100px; width: 100px;background-color: #ccc;"

block

/view

用选择器选择相应的组件进行相应的动画

进行关键帧的处理

onLoad: function () {

? this.animate('#container', [

? ? { opacity: 1.0, rotate: 0, backgroundColor: '#FF0000' },

? ? { opacity: 0.5, rotate: 45, backgroundColor: '#00FF00' },

? ? { opacity: 1.0, rotate: 90, backgroundColor: '#FF0000' },

? ], 5000)

? this.animate('.block', [

? ? { scale: [1, 1], rotate: 0, ease: 'ease-out' },

? ? { scale: [1.5, 1.5], rotate: 45, ease: 'ease-in'},

? ? { scale: [2, 2], rotate: 90 },

? ], 5000)

},

}

4、用第三方的库 animation.css

需要做的有

从下载css动画文件

把 .css 文件 改名成 .wxss文件(可进行相应的需改,毕竟小程序的大小限制摆在那里)

把它引入到你的app.wxss文件中

@import “动画文件的相对目录”

在用的时候把他和你的样式绑定

view class="swing" style="height: 100px; width: 100px;background-color: #ccc;"

block

/view

// 给类名为swing 的文件绑定swing 的动画

.swing{

animation: swing 5s infinite;

}

(责任编辑:IT教学网)

更多

推荐其他源码文章