参考资料:

张鑫旭  : http://www.zhangxinxu.com/wordpress/2012/09/css3-3d-transform-perspective-animate-transition/

Demo : Demo (建议移动端看,因为用了Zepto.js)

Demo截图:

Demo代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=640,user-scalable=no"/>
<title>Document</title>
<style>
*{ margin:0;padding:0;}
body,html{width:100%;height:100%; perspective:10000px;-webkit-perspective:10000px; background-color: #fff;-webkit-transition: top .5s;transition: top .5s;overflow:hidden;}
.main{ width:100%;height:100%; margin-left:120px;transform-origin: center center; }
.box{ position:relative;width:100%;height:100%;transform-style: preserve-3d;-webkit-transform-style: preserve-3d;transition: transform 1s;-webkit-transition: -webkit-transform 1s;transform-origin: 200px center; -webkit-transform-origin: 200px center; }
.box .piece{position: absolute;left:0;top:20%;width:400px;height:50%;-webkit-transition: opacity 1s, transform 1s;transition: opacity 1s, transform 1s; border:5px solid #ccc; -webkit-box-sizing: border-box; background: rgba(0,0,0,.5);transform-origin: center center;-webkit-transform-origin: center center; }
.box .piece:nth-child(1){ background-color: red;}
.box .piece:nth-child(2){ background-color: blue;}
.box .piece:nth-child(3){ background-color: yellow;}
.box .piece:nth-child(4){ background-color: pink;}
.box .piece:nth-child(5){ background-color: purple;}
.box .piece:nth-child(6){ background-color: black;}
.box .piece:nth-child(7){ background-color: white;}
.box .piece:nth-child(8){ background-color: gray;}
.box .piece:nth-child(9){ background-color: orange;}
.box .piece:nth-child(10){ background-color: violet;}
</style>
<script src="zepto.min.js"></script>
<script>
$(function(){ var $oBox = $('#box'),
$aPieces = $oBox.find('.piece'),
winWidth = $(window).width(),
transform = (function(){ var arr = [ 'transform','webkitTransform','mozTransform','oTransform','msTransform' ];
var oDiv = document.createElement('div'); for( var i=0,len=arr.length;i<len;i++ ){ if( oDiv.style[ arr[i] ] != undefined ){
return arr[i];
} } })(); for( var i=0,len=$aPieces.length;i<len;i++ ){ var deg = 360/len*i;
var imgWidth = $aPieces.eq(i).width()/2;
var piecesWidth = $aPieces.eq(0).width();
var z = imgWidth/Math.tan(360/len/ 180 * Math.PI) + piecesWidth ; $aPieces[i].style[ transform ] = " rotateY("+ deg +"deg) translateZ("+ z +"px)"; } var num = 0;
var oBox = document.querySelector('#box'); $(document).swipeLeft(function(){ num++;
var left = -(360 / $aPieces.length)*num;
oBox.style[ transform ] = 'rotateY('+left+'deg)'; return false; }); $(document).swipeRight(function(){ num--;
var left = -(360 / $aPieces.length)*num;
oBox.style[ transform ] = 'rotateY('+left+'deg)'; return false; }); }) </script>
</head>
<body>
<div class="main" >
<div class="box" id="box" >
<div class="piece" >1</div>
<div class="piece" >2</div>
<div class="piece" >3</div>
<div class="piece" >4</div>
<div class="piece" >5</div>
<div class="piece" >6</div>
<div class="piece" >7</div>
<div class="piece" >8</div>
<div class="piece" >9</div>
<div class="piece" >10</div>
</div>
</div>
</body>
</html>

后记:

其实看完这个 张鑫旭 的文章就应该会做了,因为我这的当时是最近看了支付宝芝麻信用里的信用猜猜那个想做的这个demo 最开始以为是围着一个点转圈做的后来想到 张鑫旭 文章跟着做了这个

主要还是根据Math.tan求这个z轴的距离然后就是perspective景深的设置,像 向左滑动,向右滑动偷懒用了 Zepto.js 的 swipeLeft、swipeRight 事件,其实想根据这个有多少面去算这个 两个 面的间隔但是后来发现没什么规律所以放弃了,当然如果有好的建议谢谢告知。

css3 - 旋转的木马的更多相关文章

  1. css3旋转倾斜3d小动画

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  2. css3旋转小三角

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. 可控制转速CSS3旋转风车特效

    以前制作网页动画一般使用javascript,现在已经有越来越多动动画使用纯CSS实现,并且动画的控制也可以使用CSS3实现,因为CSS 3来了,CSS 3的动画功能确实强大.以下是一个纯CSS3制作 ...

  4. CSS3 旋转 太阳系

    参考https://www.tadywalsh.com/web/cascading-solar-system/ 首先 旋转有两种方式  一种是使用 transform-origin  另一种是tran ...

  5. css3旋转

    首先创建一个容器如div,然后设置其相关的3d属性,主要是三个1.perspective 透视,值越小3D感越强,值越大视觉正常.2.perspective-origin,透视点一般居于容器的中心.3 ...

  6. CSS3 旋转代码备忘

    .Aclose { -webkit-transition-property: all; -webkit-transition-duration: .3s; -moz-transition-proper ...

  7. CSS3旋转缩放移动倾斜等效果——transform

    1.transform浏览器支持情况 也就是说目前不考虑老浏览器的话是不用加前缀的,感谢菜鸟教程:https://www.runoob.com/cssref/css3-pr-transform.htm ...

  8. css3旋转、过渡、动画属性

    1.transform 该属性对元素进行旋转.缩放.移动和倾斜 translate元素从当前位置移动 rotate元素顺时针旋转 scale元素的尺寸增大或减小 skew元素翻转 2.transiti ...

  9. css3旋转立方体-_-

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

随机推荐

  1. bzoj千题计划319:bzoj2865: 字符串识别(后缀自动机 + 线段树)

    https://www.lydsy.com/JudgeOnline/problem.php?id=2865 同上一篇博客 就是卡卡空间,数组改成map #include<map> #inc ...

  2. HDU 1022(火车过站 栈)

    题意是给定火车进站的序列和出站的序列,问能否完成转换,若能输出过程. 和另一道以火车进站为背景的栈应用题类似,但增加了对于过程的输出,只需要多记录一下进出站顺序即可. #include <bit ...

  3. HDU 1014(互质数 **)

    题意是说从 0 开始每次增加 STEP,然后模 MOD 得到一些数,问是否能得到从 0 到 MOD - 1 的所有数. 只要 STEP 与 MOD 互质就可以满足条件,也就是二者的最大公因数为 1 即 ...

  4. parseDouble()方法

    String a = "269"; double parseDouble = Double.parseDouble(b); System.out.println(“Double a ...

  5. Sql分页代码示例

    select * from (select ROW_NUMBER()over( order by id) orderid,* from test) a where a.orderid between ...

  6. Javaweb学习笔记——(十)——————response对象,response字符流缓冲器,响应头,状态码,重定向,requset对象,路径和乱码

    请求响应对象: request和response *当服务器接收都请求后,服务器会创建request和response对象,把请求数据封装到request对象中: *然后调用Servlet的sevic ...

  7. mybatis的两个核心对象SqlSessionFactory和SqlSession对象

    mybatis的两个核心对象SqlSessionFactory和SqlSession对象 参见:https://www.cnblogs.com/wxdestiny/p/9743686.html

  8. Java基础_0205: 程序逻辑结构

    使用if语句进行判断 public class TestDemo { public static void main(String args[]) { double score = 90.0; // ...

  9. linux C遍历目录下文件

    参考链接: http://blog.sina.com.cn/s/blog_626b7339010161tr.html

  10. python 数据分析3

    本节概要 pandas简介 安装 pip install pandas pandas的2个主要数据结构:DataFrame 和 Series Series series是一种类似于一维数组的对象,它由 ...