明霞山资源网 Design By www.htccd.com
先来看看第一种实现方式
效果图如下:
不再采用ul li的布局方式
-webkit-transform-style:preserve-3d只对子元素有作用,所以每个div都加。
实例源码
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
.wrap{margin:30px auto;width:302px;-webkit-perspective:800px; -webkit-transform-style:preserve-3d; position:relative;}
.wrap div{ position:absolute; top:52px;left:0;-webkit-transform-style:preserve-3d; -webkit-transform-origin:top;}
.wrap span{ display:block;width:300px;border:1px solid #000;height:50px; font:16px/50px "宋体"; background:#ccc;}
</style>
</head>
<body>
<input type="button" value="展开" />
<input type="button" value="收缩" />
<div class="wrap" id="list">
<span>第一项</span>
<div>
<span>第二项</span>
<div>
<span>第三项</span>
<div>
<span>第四项</span>
<div>
<span>第五项</span>
<div>
<span>第六项</span>
<div>
<span>第七项</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
window.onload=function()
{
var oList=document.getElementById("list");
var aDiv=oList.getElementsByTagName("div");
var aBtn=document.getElementsByTagName("input");
aBtn[1].onclick=function()
{
for(var i=0;i<aDiv.length;i++)
{
aDiv[i].style.transition="0.5s "+(aDiv.length-i)*100+"ms";
aDiv[i].style.WebkitTransform="rotateX(60deg)";
}
};
aBtn[0].onclick=function()
{
for(var i=0;i<aDiv.length;i++)
{
aDiv[i].style.transition="0.5s "+i*100+"ms";
aDiv[i].style.WebkitTransform="rotateX(0deg)";
}
};
};
</script>
</body>
</html>
第二种实现方式
效果图如下:
这个原先是隐藏的,点击后才展开。
通过关键帧控制每个div的展开状态,当要展开的时候给每个div添加className,但是这个className不是一下子全部添加上去的,而是有延时的,所以用到了定时器。
实例源码
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
@-webkit-keyframes open{
0%
{
-webkit-transform:rotateX(-120deg);
}
40%
{
-webkit-transform:rotateX(30deg);
}
60%
{
-webkit-transform:rotateX(-20deg);
}
80%
{
-webkit-transform:rotateX(10deg);
}
100%
{
-webkit-transform:rotateX(0deg);
}
}
.wrap{margin:30px auto;width:300px;-webkit-perspective:800px;position:relative;}
.wrap h2{ height:50px;background:#F03; text-align:center; font:16px/50px "微软雅黑"; color:#fff; position:relative;z-index:2;}
.wrap div{ position:absolute; top:32px;left:0;-webkit-transform-style:preserve-3d; -webkit-transform-origin:top; -webkit-transform:rotateX(-120deg); transition:.5s;}
.wrap>div{ top:50px;}
.wrap .open{-webkit-animation:open 2s;-webkit-transform:rotateX(0deg);}
.wrap span{ display:block;width:300px;height:30px; font:14px/30px "宋体"; background:#6F3; text-indent:15px; color:#fff; transition:.5s; box-shadow:inset 0 0 30px 20px rgba(0,0,0,1);}
.wrap .open>span{box-shadow:inset 0 0 30px 10px rgba(0,0,0,0);}
.wrap span:hover{ background:#FF0;text-indent:30px;}
</style>
</head>
<body>
<input type="button" value="展开" />
<input type="button" value="收缩" />
<div class="wrap" id="list">
<h2>标题</h2>
<div>
<span>第一项</span>
<div>
<span>第二项</span>
<div>
<span>第三项</span>
<div>
<span>第四项</span>
<div>
<span>第五项</span>
<div>
<span>第六项</span>
<div>
<span>第七项</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
window.onload=function()
{
var oList=document.getElementById("list");
var aDiv=oList.getElementsByTagName("div");
var aBtn=document.getElementsByTagName("input");
var oTimer=null;
aBtn[1].onclick=function()
{
var i=aDiv.length-1;
clearInterval(oTimer);
oTimer=setInterval(function(){
aDiv[i].className="";
i--;
if(i<0)
{
clearInterval(oTimer);
}
},50);
};
aBtn[0].onclick=function()
{
var i=0;
clearInterval(oTimer);
oTimer=setInterval(function(){
aDiv[i].className="open";
i++;
if(i==aDiv.length)
{
clearInterval(oTimer);
}
},200);
};
};
</script>
</body>
</html>
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。
明霞山资源网 Design By www.htccd.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
明霞山资源网 Design By www.htccd.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。



