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

编程学习 2021-07-04 19:20www.dzhlxh.cn编程入门
本文主要介绍js实现上下左右弹框划出效果的实例,具有很好的参考价值。狼蚁网站SEO优化跟着长沙网络推广一起来看下吧

效果图:

图(1)初始图

图(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">从狼蚁网站SEO优化划上</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>

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

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板