首页 技术 正文
技术 2022年11月7日
0 收藏 941 点赞 333 浏览 1720 个字

CSS3新增了很多新的属性,可以用很少的代码实现炫酷的动画效果,但由于兼容性各浏览器的能力存在不足,有特别需求的网站就呵呵啦。H5C3已是大势所趋了,之前看过一个新闻,Chrome将在年底全面转向H5,抛弃了Flash。。

本案例主要使用了CSS3中的变换transform和动画animation属性,实现了跑马灯效果,详细的解释在代码中的注释中。

做好布局之后的效果图

CSS3——3D旋转图(跑马灯效果图)

  添加了animation样式,实现自动旋转,并且鼠标移入,停止动画。(鼠标移入,绕Z轴旋转90度)

CSS3——3D旋转图(跑马灯效果图)

代码:

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>3D旋转</title>
<script src='jquery-3.0.0.min.js'></script>
<style>
* {
margin: 0;
padding: 0;
}
.container {
/*指定观察者与平面的距离,使有透视效果*/
/*若无法正常3d效果,将perspective属性提到更上一个父容器即可(此处已上提,从items-->container)*/
perspective: 1000px;
/*让container的伪类有过渡效果--51-54行*/
/*transition: all 1s;*/
}
.items {
width: 200px;
height: 200px;
border: 1px solid #c18;
margin: 200px auto;
/*指定子元素定位在三维空间内*/
transform-style: preserve-3d;
/*让所有item的父级元素(即items)旋转,item就是围绕着旋转了*/
animation: autoMove 10s infinite linear; }
.item {
width: 200px;
height: 200px;
background-color: skyblue;
opacity: .6;
font-size: 200px;
line-height: 200px;
text-align: center;
position: absolute;
}
/*定义自动旋转的动画*/
@keyframes autoMove {
from { }
to {
transform: rotateY(-360deg);
}
}
.items:hover {
/*鼠标移入 暂停动画*/
animation-play-state: paused;
}
.container:hover {
/*鼠标移入,绕Z轴旋转90deg*/
/*transform: rotateZ(90deg);*/
}
</style>
<script>
$(function () {
var itemNum = $(".container .items .item").length;//要旋转的div的数量
var itemDeg = 360 / itemNum;//计算平均偏移角度,后面的itemDeg*index是不同索引div的偏移角度
$(".items>.item").each(function (index, element) {
$(element).css({
//给每一个item设置好位置
//rotateY让每一个item绕着Y轴偏移,itemDeg*index是不同索引div的偏移角度
//translateZ是控制item在角度偏移后,往他们的正上方移动的距离,数值越大旋转的范围越大
transform: "rotateY(" + itemDeg * index + "deg) translateZ(280px)"
});
});
});
</script>
</head>
<body>
<div class="container">
<div class="items">
<!--简便起见,用背景色和数字代替图片-->
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
</div>
</div>
</body>
</html>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,020
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,359
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,142
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,772
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,850