时间:2021-07-01 10:21:17 帮助过:162人阅读
<!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"/> <link href="css/reset.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="../../jquery-1.8.3.js"></script> <script type="text/javascript"> // alert( 64 / Math.tan(20 / 180 * Math.PI)); var transform = function (element, value, key) { key = key || "Transform"; ["Moz", "O", "Ms", "Webkit", ""].forEach(function (prefix) { element.style[prefix + key] = value; }); return element; } $(function () { var deg = -40 , i = 1; $("#container").click(function () { transform($(this)[0], "rotateY(" + (deg * i++) + "deg)") }); }); </script> </head> <body> <p id="stage"> <ul id="container"> <li> <img src="img/1.jpg"/> <span>Do one thing at a time, and do well..</span> </li> <li> <img src="img/2.jpg"/> <span>Do one thing at a time, and do well..</span> </li> <li> <img src="img/3.jpg"/> <span>Keep on going never give up.</span> </li> <li> <img src="img/4.jpg"/> <span>Whatever is worth doing is worth doing well.</span> </li> <li> <img src="img/5.jpg"/> <span>Believe in yourself.</span> </li> <li> <img src="img/6.jpg"/> <span>Action speak louder than words.</span> </li> <li> <img src="img/7.jpg"/> <span>Never put off what you can do today until tomorrow.</span> </li> <li> <img src="img/8.jpg"/> <span>Jack of all trades and master of none.</span> </li> <li> <img src="img/9.jpg"/> <span>Judge not from appearances.</span> </li> </ul> </p> </body> </html>
CSS:
li { width: 128px; box-shadow: 0 1px 3px rgba(0, 0, 0, .5); position: absolute; bottom: 0; } li img { width: 128px; box-shadow: 0 1px 3px rgba(0, 0, 0, .5); vertical-align: middle; } li span { display: block; width: 128px; text-align: center; color: #333; font-size: 8px; } #stage { width: 900px; min-height: 100px; margin-left: auto; margin-right: auto; padding: 100px 50px; -webkit-perspective: 1200px; position: relative; } #container { background: url("img/xawl.jpg") no-repeat 0 0; margin-top: 200px; width: 128px; box-shadow: 0 1px 3px rgba(0, 0, 0, .5); height: 100px; margin-left: -64px; -webkit-transition: -webkit-transform 1s; transition: transform 1s; -webkit-transform-style: preserve-3d; position: absolute; left: 50%; } li:nth-child(0) { -webkit-transform: rotateY(0deg) translateZ(300px); } li:nth-child(1) { -webkit-transform: rotateY(40deg) translateZ(300px); } li:nth-child(2) { -webkit-transform: rotateY(80deg) translateZ(300px); } li:nth-child(3) { -webkit-transform: rotateY(120deg) translateZ(300px); } li:nth-child(4) { -webkit-transform: rotateY(160deg) translateZ(300px); } li:nth-child(5) { -webkit-transform: rotateY(200deg) translateZ(300px); } li:nth-child(6) { -webkit-transform: rotateY(240deg) translateZ(300px); } li:nth-child(7) { -webkit-transform: rotateY(280deg) translateZ(300px); } li:nth-child(8) { -webkit-transform: rotateY(320deg) translateZ(300px); } li:nth-child(9) { -webkit-transform: rotateY(360deg) translateZ(300px); }
p#stage作为舞台,设置perspective,每个li分别设置rotateY,以及translateZ;然后我们会p#container设置了-webkit-transform-style: preserve-3d;transform-style: flat | preserve-3d其中flat值为默认值,表示所有子元素在2D平面呈现。preserve-3d表示所有子元素在3D空间中呈现。如果对一个元素设置了transform-style的值为preserve-3d,它表示不执行平展操作,他的所有子元素位于3D空间中。一般情况下,此属性用于3D动画效果的执行元素,即就是它要应用3D动画效果,所以它的子元素都应该在3D空间。
有一点要注意:本例子,其实正在的动画效果,在于鼠标点击,p#Container在不端的改变rotateY,所有的图片元素均在p#container中,且已经展现为旋转木马效果,现在要做的就是旋转这个木马,所以只需要每次改变p#container的rotateY 40角度即可。
以上就是HTML5 css3:3D旋转木马效果相册 的内容,更多相关内容请关注PHP中文网(www.gxlcms.com)!