案例1:旋轉(zhuǎn)的輪播圖
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
body {
perspective: 1000px;
}
section {
width: 300px;
height: 200px;
margin: 100px auto;
background: url(../3D/images/1.jpg) no-repeat;
background-size: cover;
position: relative;
transform-style: preserve-3d; /* 讓父盒子里面的子盒子以3d效果顯示 */
transition: 5s linear; /* 勻速 all 是可以省略的, 省略默認(rèn)的all*/
}
section:hover {
transform: rotateY(360deg);
}
section div {
width: 100%;
height: 100%;
background: url(../3D/images/2.jpg) no-repeat;
background-size: cover;
position: absolute;
top: 0;
left: 0;
}
section div:nth-child(1) {
transform: rotateY(0deg) translateZ(400px);
}
section div:nth-child(2) {
transform: rotateY(60deg) translateZ(400px);
}
section div:nth-child(3) {
transform: rotateY(120deg) translateZ(400px);
}
section div:nth-child(4) {
transform: rotateY(180deg) translateZ(400px);
}
section div:nth-child(5) {
transform: rotateY(240deg) translateZ(400px);
}
section div:nth-child(6) {
transform: rotateY(300deg) translateZ(400px);
}
</style>
</head>
<body>
<section>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
</body>
</html>
案例2:開門大吉
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
section {
width: 450px;
height: 300px;
border: 1px solid #000;
margin: 100px auto;
background: url(images/1.jpg) no-repeat;
position: relative;
perspective: 1000px; /*給父盒子添加透視效果*/
}
.door-l, .door-r {
position: absolute;
top: 0;
width: 50%;
height: 100%;
background-color: pink;
transition: all 1s; /*兩個(gè)門都做過(guò)渡效果*/
background: url(images/bg.png);
}
.door-l {
left: 0;
border-right: 1px solid #000;
transform-origin: left;/* 左側(cè)盒子按照左邊翻轉(zhuǎn)*/
}
.door-r {
right: 0;
left: 1px solid #000;
transform-origin: right;/* 右側(cè)盒子按照右邊翻轉(zhuǎn)*/
}
.door-l::before, .door-r::before { /*偽元素 就是插入一個(gè)元素標(biāo)簽*/
content: '';
position: absolute;
top: 50%;
width: 20px;
height: 20px;
border: 1px solid #000;
border-radius: 50%; /*圓角*/
transform:translateY(-50%); /*translate 如果是百分比, 就是走自己高度的一半*/
}
.door-l::before {
right: 5px;
}
.door-r::before {
left: 5px;
}
/*鼠標(biāo)經(jīng)過(guò)section 盒子 兩個(gè)門盒子 翻轉(zhuǎn) rotateY*/
section:hover .door-l {
transform: rotateY(-130deg); /*因?yàn)橥筮叿D(zhuǎn),所以是負(fù)值*/
}
section:hover .door-r {
transform: rotateY(130deg);
}
</style>
</head>
<body>
<section>
<div class="door-l"></div>
<div class="door-r"></div>
</section>
</body>
</html>
案例3:導(dǎo)航欄旋轉(zhuǎn)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>3d導(dǎo)航</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
ul {
/*取消ul的默認(rèn)樣式*/
list-style: none;
margin: 90px auto;
width: 800px;
}
ul li {
width: 160px;
height: 50px;
float: left;
position: relative;
/*設(shè)置子元素顯示方式為3d*/
transform-style:preserve-3d;
/*設(shè)置旋轉(zhuǎn)的過(guò)渡效果*/
transition: transform 1s;
}
li a {
position: absolute;
/*設(shè)置了相對(duì)定位的元素,默認(rèn)具有塊元素的特點(diǎn)*/
/*取消a鏈接的默認(rèn)下劃線*/
text-decoration: none;
text-align: center;
line-height: 50px;
color: #fff;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.8);
top: 0;
left: 0;
width: 100%;
height: 100%;
}
li a:first-child {
transform: translateZ(25px);
background-color: #ff5544;
}
li a:last-child {
background-color: skyblue;
transform: rotateX(-90deg) translateZ( 25px );
}
li:hover {
transform: rotateX(90deg);
}
</style>
</head>
<body>
<ul>
<li>
<a href="#">信息科學(xué)與工程學(xué)院</a>
<a href="#">Javaweb專業(yè)</a>
</li>
<li>
<a href="#">信息科學(xué)與工程學(xué)院</a>
<a href="#">Javaweb專業(yè)</a>
</li><li>
<a href="#">信息科學(xué)與工程學(xué)院</a>
<a href="#">Javaweb專業(yè)</a>
</li><li>
<a href="#">信息科學(xué)與工程學(xué)院</a>
<a href="#">Javaweb專業(yè)</a>
</li><li>
<a href="#">信息科學(xué)與工程學(xué)院</a>
<a href="#">Javaweb專業(yè)</a>
</li>
</ul>
</body>
</html>