为了账号安全,请及时绑定邮箱和手机立即绑定

CSS3 3D效果

不知道什么地方出错了,不翻页,谷歌显示”Cannot read property 'style' of null“,这个要怎么修改啊???

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>无标题文档</title>

<style type="text/css">

    #my3d{

        -webkit-perspective:800px;

        -webkit-perspective-origin:50% 50%;


        overflow:hidden;

    }

    

    #book{

        width:400px;

        height:400px;

        margin:0 auto;

        

        -webkit-transform-style:preserve-3d;

        

        position:relative;

    }

    

    .page{

        width:400px;

        height:400px;

        background-color:black;

        

        color:white;

        

        font-weight:bold;

        font-size:380px;

        line-height:380px;

        text-align:center;

        

        position:absolute;

}

    #p1{

        -webkit-transform-origin:bottom;

        -webkit-transition:-webkit-transform 1s linear;

    }

#p2,#p3,#p4,#p5,#p6{

     -webkit-transform-origin:bottom;

    -webkit-transition:-webkit-transform 1s linear;

    -webkit-transform:rotateX(90deg);

    }

#po{

    text-align:center;

    margin:40px auto;

}

</style>

<script type="text/javascript">

var index=1;

function next(){

   if(index==6){

return;

}

   var index=document.getElementById("p"+index);

index.style.webkitTransform="rotateX(-90deg)";

index++;

var nextindex=document.getElementById("p"+index);

nextindex.style.webkitTransform="rotateX(0deg)";

}

function pre(){

   if(index==1){

return;

}

   var index=document.getElementById("p"+index);

index.style.webkitTransform="rotateX(90deg)";

index--;

var preindex=document.getElementById("p"+index);

preindex.style.webkitTransform="rotateX(0deg)";

}

</script>

</head>

<body>

    <div id="my3d">

        <div id="book">

            <div class="page" id="1">1</div>

            <div class="page" id="p2">2</div>

            <div class="page" id="p3">3</div>

            <div class="page" id="p4">4</div>

            <div class="page" id="p5">5</div>

            <div class="page" id="p6">6</div>

        </div>

    </div>

    

    <div id="po">

        <a href="javascript:next()">next</a>

        <a href="javascript:pre()">pre</a>

    </div>

</body>

</html>


正在回答

1 回答

 var index=document.getElementById("p"+index);

变量定义重复了,换个名字,比如 var p =

1 回复 有任何疑惑可以回复我~
#1

zxjiao 提问者

非常感谢!运行出来了!
2016-08-21 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
CSS3 3D 特效
  • 参与学习       78578    人
  • 解答问题       425    个

使用CSS3当中的属性,创建真实可用的三维效果

进入课程

CSS3 3D效果

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信