zoukankan      html  css  js  c++  java
  • css3 animate写的超炫3D转换

    上一篇中介绍了animate的基本的属性,这一篇讲的则是关于animate以及transforms的使用

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>css3超炫3维转换</title>
    <style>
    *{
    padding: 0px;
    margin: 0px;
    }
    .box li{
    list-style: none;
    }
    .out{
    800px;
    height: 400px;
    margin: 100px auto;
    position: relative;
    /*perspective: 1000px;*/
    }
    .box{
    800px;
    height: 100px;
    transform-style: preserve-3d;
    position: absolute;
    transform-origin: center center 25px;
    transition: 2s all ease-in-out;
    }
    .box li{
    position: absolute;
    }
    ul li:nth-of-type(1){
    800px;
    height: 50px;
    top: -50px;
    background-color: #eaeaea;
    -webkit-transform-origin: bottom;
    -webkit-transform: rotateX(-90deg);
    }
    ul li:nth-of-type(2){
    height:100px;
    50px;
    left: -50px;
    background-color: #eaeaea;
    -webkit-transform-origin: right;
    -webkit-transform: rotateY(90deg);
    }
    ul li:nth-of-type(3){
    height: 100px;
    800px;
    -webkit-transform-origin: center;
    -webkit-transform: rotateY(180deg);
    background: url(3D2.jpg)no-repeat;

    }
    ul li:nth-of-type(4){
    height: 100px;
    50px;
    left: 800px;
    background-color: #eaeaea;
    -webkit-transform-origin: left;
    -webkit-transform: rotateY(-90deg);
    }
    ul li:nth-of-type(5){
    100px;
    height: 50px;
    top:100px;
    background-color: #eaeaea;
    -webkit-transform-origin: top;
    -webkit-transform: rotateX(90deg);
    }
    ul li:nth-of-type(6){
    height: 100px;
    800px;
    background:url(3D3.jpeg)no-repeat;
    }
    #btn{
    100px;
    background-color: black;
    border-radius: 5px;
    margin: 0 auto;
    color:white;
    font: 20px/40px"微软雅黑";
    text-align: center;
    cursor: pointer;
    }
    </style>
    <script src="css3.js"></script>
    <script>
    /*
    实现目标效果: 1.将图片分成四部分,则每部分的高度为100px,添加进out中
    2.添加鼠标事件
    */
    window.onload = function (){
    var out = document.getElementById('out');
    add(out);
    var btn = document.getElementById('btn');
    var box =document.getElementsByTagName('ul');
    var angle = 0;
    btn.onclick=function (){
    angle+=180;
    if(angle>180)angle=0;
    for(var j = 0;j<4;j++){
    setCss3(box[j],{transform:"rotateY("+angle+"deg)"});
    }
    }
    }
    //添加box的函数
    function add(obj){
    // 创建一个数组,然后通过for添加一个四个ul对象;
    var str = '';
    for(var i=0;i<4;i++){
    str+='<ul class="box" style="top:'+i*100+'px;transition-delay:'+i/4+'s"><li></li><li></li><li style="background-position:0px '+-i*100+'px;"></li><li></li><li></li><li style="background-position:0px '+-i*100+'px;"></li></ul>';
    }
    //将str数组添加在obj中
    obj.innerHTML=str;
    }
    </script>
    </head>
    <body>
    <!-- 实现图片的分割3D旋转效果

    实现的效果:1.点击按钮的时候,图片翻转,并且是分割式旋转180度。

    实现的步骤: 1.布局,布局3D盒子,并将图片放置在盒子的正面和反面,设置好盒子的样式。
    2.将不知的布置的盒子样式保留,去掉body中的标签。
    3.通过javascript添加四个盒子,每个盒子中背景图片都是同一张图片,并通过设置背景图片的position来控制每个盒子显示出不同的位置。
    4.鼠标点击事件,每次翻转角度为180度。通过改变过渡模式来使图片实现分割式旋转
    -->
    <div class="out" id="out">

    </div>
    <div id="btn">更换</div>
    </body>
    </html>

    可以直接复制使用

  • 相关阅读:
    Property总结
    静态类和 关于什么时候使用“静态方法”
    最简单的MVVM结构(学习)
    依赖属性和附加属性1(转载)
    Nested & Access modifiers
    Template methord
    WPF 绑定及惯用法(一) 转载自loveis715
    关于Property赋值
    Different Binding RelativeSource Mode
    依赖属性和附加属性2(转载)
  • 原文地址:https://www.cnblogs.com/TzSteady/p/7396891.html
Copyright © 2011-2022 走看看