zoukankan      html  css  js  c++  java
  • CSS 3D旋转 hover 后设置transform 是相对于正常位置

    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title>Document</title>
    </head>
    <style type="text/css">
    	.nav{
    		 980px;
    		margin: 50px auto;
    		background-color: #fdfdfd;
    		border: 1px #ccc solid;
    	}
    	.nav:after{
    		clear: both;
    		display: block;
    		overflow: hidden;
    		content: "";
    	}
    	.nav .item{
    		200px;
    		height: 100px;
    		margin-right: 5px;
    		float: left;
    		perspective:400px;
    	}
    	.nav .item a{
    		display: block;
    		height: 100px;
    		text-decoration: none;
    		transition:all .5s;
    		transform-style:preserve-3d;
    	}
    	.nav .item a p{
    		height: 100px;
    		margin:0;
    		line-height: 100px;
    		color: #fff;
    		text-align:center;
    		font-size: 20px;
    		font-family: "Microsoft Yahei";
    		border-radius: 2px;
    		transition:all .5s;
    	}
    	
    	.nav .item a p:first-child{
    		background-color: #090;
    		transform:translateZ(50px);
    
    	}
    	.nav .item a p:last-child{
    		background-color: #009;
    		/*这样会向结果方向走50px像素*/
    		transform:translateZ(50px) rotateX(-90deg) ;
    		/*margin-top: -50px;*/
    	}
    	/*立体旋转是按面在转*/
    	.nav .item a:hover{
    		transform:rotateX(90deg);
    	}
    	/*这东西是基于正常位置,而不是动画的位置如(transform:translateZ(50px) rotateX(-90deg) ;)*/
    	.nav .item a:hover p:last-child{
    		margin-top: 0;
    		transform: translateZ(0) rotateX(-90deg);
    	}
    </style>
    <body>
    	<header class="nav">
    		<div class="item">
    			<a href="#">
    				<p>首页</p>
    				<p>Home</p>
    			</a>
    		</div>
    
    		<div class="item">
    			<a href="#">
    				<p>问答</p>
    				<p>Q & A</p>
    			</a>
    		</div>
    
    		<div class="item">
    			<a href="#">
    				<p>关于我们</p>
    				<p>About us</p>
    			</a>
    		</div>
    	</header>
    </body>
    </html>
    

      之前一直想不通,如下为什么旋转到上面后要再旋转-90deg。

    	/*这东西是基于正常位置,而不是动画的位置如(transform:translateZ(50px) rotateX(-90deg) ;)*/
    	.nav .item a:hover p:last-child{
    		margin-top: 0;
    		transform: translateZ(0) rotateX(-90deg);
    	}

    另外rotateX(-90deg)是上边缘向屏幕外旋转,也就是顺时针。反之。
  • 相关阅读:
    [转]VC++ ^和gcnew
    OPPM 一页纸项目管理 OnePage Project Management
    [转]基础总结篇之五:BroadcastReceiver应用详解 .
    [转]深入浅出Java设计模式之备忘录模式
    [转]面向对象的5条基本设计原则
    [转]UED大全
    [转]VC++动态链接库(DLL)编程深入浅出(zz)
    只有壮年时的不遗余力 才能支撑一生的坎坷与幸福
    [书目20121024]当责 AccountaBility
    node.js入门
  • 原文地址:https://www.cnblogs.com/yqlog/p/5515402.html
Copyright © 2011-2022 走看看