欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

js实现上下左右弹框划出效果

程序员文章站 2022-10-14 21:33:34
效果图: 图(1)初始图 图(2)点击“从右侧划出” 代码如下: <...

效果图:

js实现上下左右弹框划出效果

图(1)初始图

js实现上下左右弹框划出效果

图(2)点击“从右侧划出”

代码如下:

<!doctype html>
<html>
 <head>
 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
 <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
 <title>上下左右弹框划出效果</title>
 <style>
   /*css document*/
body,div,ol,ul,li,dl,dt,dd,h1,h2,h3,h4,h5,h6,p,form,fieldset,legend,input,button,aside{ padding: 0; margin: 0; -webkit-tap-highlight-color:rgba(255,255,255,0);}
   body { font-family: "microsoft yahei"; }
   .btn button {
 display: block;
 width: 240px; 
 line-height: 30px;
 margin: 20px auto;
 background-color: #cd0000;
 color: #fff;
 text-align: center;
 outline: none;
 border: none;
 cursor: pointer;
 font-family: "microsoft yahei";
}
.aside,
.aside-overlay {
 position: fixed;
 top: 0;
 right: 0;
 left: 0;
 bottom: 0;
}
.aside {
 -webkit-transition: visibility .25s;
 transition: visibility .25s;
 z-index: 3;
 visibility: hidden;
 overflow: hidden;
}
.aside > div { text-align: center; }
.aside.active {
 -webkit-transition: none;
 transition: none;
 visibility: visible;
}
.aside-overlay {
 background-color: rgb(0,0,0);
 opacity: 0;
 -webkit-transition: opacity .25s;
 transition: opacity .25s;
}
.active > .aside-overlay {
 opacity: .6;
}
.rightcontent {
 position: absolute;
 bottom: 0;
 right: 0;
 top: 0;
 left: 40px;
 background:#fff;
 -webkit-transition: transform .15s;
 transition: transform .15s;
 -webkit-transform:translatex(100%); 
 transform:translatex(100%); 
}
.active > .rightcontent {
 -webkit-transform:translatex(0%); 
 transform:translatex(0%); 
}
.leftcontent {
 position: absolute;
 bottom: 0;
 right: 40px;
 top: 0;
 left: 0;
 background:#fff;
 -webkit-transition: transform .15s;
 transition: transform .15s;
 -webkit-transform:translatex(-100%); 
 transform:translatex(-100%); 
}
.active > .leftcontent {
 -webkit-transform:translatex(0%); 
 transform:translatex(0%); 
}
.topcontent {
 position: absolute;
 bottom: 40px;
 right: 40px;
 top: 0;
 left: 40px;
 background:#fff;
 -webkit-transition: transform .15s,top .15s;
 transition: transform .15s;
 -webkit-transform:translatey(-100%); 
 transform:translatey(-100%); 
}
.active > .topcontent {
 top: 40px;
 -webkit-transform:translatey(0%); 
 transform:translatey(0%); 
}
.botcontent {
 position: absolute;
 bottom: 0;
 right: 40px;
 top: 40px;
 left: 40px;
 background:#fff;
 -webkit-transition: transform .15s,bottom .15s;
 transition: transform .15s;
 -webkit-transform:translatey(100%); 
 transform:translatey(100%); 
}
.active > .botcontent {
 bottom: 40px;
 -webkit-transform:translatey(0%); 
 transform:translatey(0%); 
}
  </style>
 </head>
 <body>
 <!-- 按钮 -->
 <div class="btn">
 <button id="rightbtn">从右侧划出</button>
 <button id="leftbtn">从左侧划出</button>
 <button id="topbtn">从上面划下</button>
 <button id="botbtn">从下面划上</button>
 </div>
 <!-- 弹出层 -->
 <aside id="aside" class="aside">
 <i class="aside-overlay hideaside"></i>
 <div class="rightcontent">
 右侧划出
 </div>
 <div class="leftcontent">
 左侧划出
 </div>
 <div class="topcontent">
 从上面划下
 </div>
 <div class="botcontent">
 从上面划下
 </div>
 </aside>
 <script type="text/javascript" src="http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
 <script type="text/javascript">
 $(function(){
 var rightbtn = $('#rightbtn'),leftbtn = $('#leftbtn'),topbtn = $('#topbtn'),botbtn = $('#botbtn');
 var oaside = $('#aside');
 rightbtn.on("click",function(){
 $('.leftcontent').hide();
 $('.topcontent').hide();
 $('.botcontent').hide();
 $('.rightcontent').show();
 oaside.addclass('active');
 });
 leftbtn.on("click",function(){
 $('.rightcontent').hide();
 $('.topcontent').hide();
 $('.botcontent').hide();
 $('.leftcontent').show();
 oaside.addclass('active');
 });
 topbtn.on("click",function(){
 $('.rightcontent').hide();
 $('.leftcontent').hide();
 $('.botcontent').hide();
 $('.topcontent').show();
 oaside.addclass('active');
 });
 botbtn.on("click",function(){
 $('.rightcontent').hide();
 $('.leftcontent').hide();
 $('.topcontent').hide();
 $('.botcontent').show();
 oaside.addclass('active');
 });
 $('.hideaside').on("click",function(){
 oaside.removeclass('active');
 });
 })
 </script>
 </body>
</html>

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!