温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

html5怎么实现菜单折纸效果

发布时间:2021-07-26 21:27:22 来源:亿速云 阅读:139 作者:chen 栏目:web开发

本篇内容主要讲解“html5怎么实现菜单折纸效果”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“html5怎么实现菜单折纸效果”吧!

类似猎豹浏览器安装时的用户须知效果。

html5怎么实现菜单折纸效果

点击后效果

html5怎么实现菜单折纸效果

代码如下:


<!DOCTYPE html>
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>fold paper effect by gt-柯乐义</title>
 <style>
#wrapper {
-webkit-perspective: 55cm;
-webkit-perspective-origin: 50% 50%;
text-align: center;
}
.paper {
position: relative;
height: 40px;
width: 5em;
margin: 0;
background-color: aqua;
-webkit-transition: -webkit-transform 1s linear;
}
</style>
 <script type="text/javascript">
window.angel = 0;
window.timer;
function fold() {
 var foldUp = document.getElementById("foldUp");
 var foldDown = document.getElementById("foldDown");
 var down = document.getElementById("down");
 if (window.angel == 0) {
  window.timer = setInterval(function() {
   var diff = different(-1, 20);
   console.log(foldUp.offsetTop)
   move(foldUp, diff, 1);
   move(foldDown, diff, 3);
   move(down, diff, 4);
  }, 40);
  setTimeout(function() {
   clearInterval(window.timer);
   foldUp.style.top = "-20px";
   foldDown.style.top = "-60px";
   down.style.top = "-80px";
   window.angel = -90;
  }, 1030);
  foldUp.style.webkitTransform = "rotateX(-90deg)";
  foldDown.style.webkitTransform = "rotateX(90deg)";
 } else if (angel == -90) {
  window.timer = setInterval(function() {
   var diff = different(1, 20);
   console.log(foldUp.offsetTop)
   move(foldUp, diff, 1);
   move(foldDown, diff, 3);
   move(down, diff, 4);
  }, 40);
  setTimeout(function() {
   clearInterval(window.timer);
   foldUp.style.top = "0";
   foldDown.style.top = "0";
   down.style.top = "0";
   window.angel = 0;
  }, 1030);
  foldUp.style.webkitTransform = "rotateX(0deg)";
  foldDown.style.webkitTransform = "rotateX(0deg)";
 } else {
  console.log(window.angel)
 }
}
function positionValue(div, type) {// 得到css带单位的值
 var str = div.style[type];
 str = str.substring(0, str.length - 2);
 var value = parseInt(str);
 if (isNaN(value)) {
  value = 0;
 }
 return value;
}
function move(div, different, time) {
 var top = positionValue(div, "top");
 div.style.top = top + different * time + "px";
}
function different(direction, height) {
 var lastAngel = window.angel;
 window.angel += 3.6 * direction;
 var different = Math
   .ceil((Math.cos(window.angel / 180 * Math.PI) - Math
     .cos(lastAngel / 180 * Math.PI))
     * height * 100) / 100;
 return different;
}
</script>
</head>
<body>
 <div id="wrapper">
  <div id="up" class="paper">
   g
  </div>
  <div id="foldUp" class="paper">
   n
  </div>
  <div id="foldDown" class="paper">
   b
  </div>
  <div id="down" class="paper">
   t
  </div>
 </div>
 <button onclick=fold();>
  fold
 </button>
</body>
</html>

到此,相信大家对“html5怎么实现菜单折纸效果”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI