css3的常用变形方法有哪些?写出核心代码

html-css014

css3的常用变形方法有哪些?写出核心代码,第1张

css3中的变形

Chrome和safai需前缀加-webkit-,Foxfire需加前缀-moz-

1,旋转 rotate()

div{

width: 300px

height: 300px

transform:rotate(20deg)

}

2,扭曲 skew()

div {

width: 300px

height: 300px

transform:skew(45deg,-10deg)

}

3,缩放 scale()

scale(X,Y)使元素水平方向和垂直方向同时缩放(也就是X轴和Y轴同时缩放)

也可以只缩放 x轴,或只缩放y轴。

div {

width: 200px

height: 200px

background: orange

}

.wrapper div:hover {

opacity: .5

transform: scale(0.8)

}

4,位移 translate()

translate()函数可以将元素向指定的方向移动,类似于position中的relative。

或以简单的理解为,使用translate()函数,可以把元素从原来的位置移动,

而不影响在X、Y轴上的任何Web组件。

5,原点 transform-origin

CSS变形进行的旋转、位移、缩放,扭曲等操作都是以元素自己中心位置进行变形。

但很多时候,我们可以通过transform-origin来对元素进行原点位置改变,使元素

原点不在元素的中心位置,以达到需要的原点位置。

div {

transform: skew(45deg)

transform-origin:top

}

6,过渡

div {

width: 200px

height: 200px

background: red

margin: 20px auto

-webkit-transition-property: all

transition-property: all //指定过渡或动态模拟的css属性 (all是指所有)

-webkit-transition-duration:5s

transition-duration:5s //指定完成过渡的时间

-webkit-transition-timing-function: linear

transition-timing-function: linear//指定过渡的函数 linear/ease/ease-in/ease-out/ease-in-out/cubicbezier(n,n,n,n) n为0-1

-webkit-transition-delay: .18s

transition-delay:.18s //指定开始出现的延迟时间

}

div:hover {

width: 400px

height:400px

}

7,Keyframes被称为关键帧,css3中以“@keyframes”开头,后面紧跟着是动画名称加上一对花括号“{...}”

@keyframes changecolor{

0%{

background: red

}

20%{

background:blue

}

40%{

background:orange

}

60%{

background:green

}

80%{

background:yellow

}

100%{

background: red

}

}

div {

width: 300px

height: 200px

}

div:hover {

animation: changecolor 5s ease-out .2s

}

等价于

div:hover{

animation-name:changecolor

animation-duration:5s

animation-timing-function:ease-out

animation-delay:1

animation-iteration-count:infinite//动画播放次数 整数。

animation-play-state:paused//主要用来控制元素动画的播放状态。

animation-direction:alternate//动画方向,normal每次循环向前,alternate偶次向前,奇数相反。

animation-fill-mode: both//设置动画时间外属性none、forwards、backwords和both

}

一、实现CSS3无限循环动画代码示例。

代码如下:

CSS:

@-webkit-keyframes gogogo {

0%{

-webkit-transform: rotate(0deg)

border:5px solid red

}

50%{

-webkit-transform: rotate(180deg)

background:black

border:5px solid yellow

}

100%{

-webkit-transform: rotate(360deg)

background:white

border:5px solid red

}

}

.loading{

border:5px solid black

border-radius:40px

width: 28px

height: 188px

-webkit-animation:gogogo 2s infinite linear

margin:100px

}

扩展资料

实现动画无限循环所需要的CSS属性说明:

1、infinite

在animation后面加上infinite就可以无限循环,另外还可以做反向循环使用animation-direction

2、animation-name

规定需要绑定到选择器的 keyframe 名称。

3、animation-duration

规定完成动画所花费的时间,以秒或毫秒计。

4、animation-timing-function

规定动画的速度曲线。

5、animation-delay

规定在动画开始之前的延迟。

6、animation-iteration-count

规定动画应该播放的次数。

7、animation-direction

规定是否应该轮流反向播放动画。

这样写吧:

<div class="meter">

<span style="width: 25%"></span>

</div>

.meter {

height: 20px /* Can be anything */

position: relative

background: #555

-moz-border-radius: 25px

-webkit-border-radius: 25px

border-radius: 25px

padding: 10px

box-shadow: inset 0 -1px 1px rgba(255,255,255,0.3)

}

.meter >span {

display: block

height: 100%

border-top-right-radius: 8px

border-bottom-right-radius: 8px

border-top-left-radius: 20px

border-bottom-left-radius: 20px

background-color: rgb(43,194,83)

background-image: linear-gradient(

center bottom,

rgb(43,194,83) 37%,

rgb(84,240,84) 69%

)

box-shadow:

inset 0 2px 9px rgba(255,255,255,0.3),

inset 0 -2px 6px rgba(0,0,0,0.4)

position: relative

overflow: hidden

}

.orange >span {

background-color: #f1a165

background-image: linear-gradient(to bottom, #f1a165, #f36d0a)

}

.red >span {

background-color: #f0a3a3

background-image: linear-gradient(to bottom, #f0a3a3, #f42323)

}

.meter >span:after {

content: ""

position: absolute

top: 0left: 0bottom: 0right: 0

background-image: linear-gradient(

-45deg,

rgba(255, 255, 255, .2) 25%,

transparent 25%,

transparent 50%,

rgba(255, 255, 255, .2) 50%,

rgba(255, 255, 255, .2) 75%,

transparent 75%,

transparent

)

z-index: 1

background-size: 50px 50px

animation: move 2s linear infinite

border-top-right-radius: 8px

border-bottom-right-radius: 8px

border-top-left-radius: 20px

border-bottom-left-radius: 20px

overflow: hidden

}