如何用css制作顺逆时针旋转的效果?

html-css0102

如何用css制作顺逆时针旋转的效果?,第1张

1、首先准备一个HTML文档,文档中准备好两个图片,接下来会对这两个图片进行旋转。

2、然后对HTML中的内容定义一些样式,如下图所示,主要是标题以及ul的样式。

3、接下来就给图片所在的li定义宽高,如下图所示。

4、然后给图片设置过渡效果,过渡使用transition属性,如下图所示。

5、当鼠标悬停在图片上时,通过rotate给其设置变形,如下图所示,正数代表的是顺时针,负数代表的是逆时针。

6、最后运行程序,会看到如下图所示的效果,鼠标放在图片上会顺时针或者逆时针旋转。

1、首先准备一个HTML文档,文档中准备好两个图片,接下来会对这两个图片进行旋转。

2、其次对HTML中的内容定义一些样式,给图片设置过渡效果,过渡使用transition属性。

3、最后正数代表的是顺时针,负数代表的是逆时针,运行程序后将鼠标放在图片上调为逆时针旋转即可。

<!doctype html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Document</title>

<style>

/*如果使用的不是webkit浏览器 请将代码中的注释都去掉就可以看到效果*/

@-webkit-keyframes clockwiseRotate{

to {

transform:rotate(90deg)

}

}

@-webkit-keyframes anticlockwiseRotate{

to {

transform:rotate(-90deg)

}

}

@-webkit-keyframes zoomScale{

to{

transform:scale(1.5)

}

}

.stage{

width:200px

margin:200px auto auto

border-left:1px solid

border-right:1px solid

}

.box{

width:100px

height:100px

transform-origin:0 0

}

.clockwise{

background-color:purple

-webkit-animation:clockwiseRotate 2s infinite

/* 设置旋转中心为左上角 顺时针旋转90度 */

/*transform-origin:0 0

transform:rotate(90deg)*/

}

.anticlockwise{

background-color:orange

-webkit-animation:anticlockwiseRotate 2s infinite

/* 设置旋转中心为左上角 逆时针旋转90度*/

/*transform-origin:0 0

transform:rotate(-90deg)*/

}

.zoom{

background-color:green

-webkit-animation:zoomScale 2s infinite

/* 设置放大中心为元素中心 放大1.5倍*/

transform-origin:50% 50%

/*transform:scale(1.5)*/

}

</style>

</head>

<body>

<div class="stage">

<div class="box clockwise"></div>

<div class="box anticlockwise"></div>

<div class="box zoom"></div>

</div>

</body>

</html>