溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

js實(shí)現(xiàn)上下左右彈框劃出效果

發(fā)布時(shí)間:2020-08-24 11:53:57 來(lái)源:腳本之家 閱讀:210 作者:留白snow 欄目:web開發(fā)

效果圖:

js實(shí)現(xiàn)上下左右彈框劃出效果

圖(1)初始圖

js實(shí)現(xiàn)上下左右彈框劃出效果

圖(2)點(diǎn)擊“從右側(cè)劃出”

代碼如下:

<!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,h2,h3,h4,h5,h6,h7,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">從右側(cè)劃出</button>
 <button id="leftBtn">從左側(cè)劃出</button>
 <button id="topBtn">從上面劃下</button>
 <button id="botBtn">從下面劃上</button>
 </div>
 <!-- 彈出層 -->
 <aside id="aside" class="aside">
 <i class="aside-overlay hideAside"></i>
 <div class="rightContent">
 右側(cè)劃出
 </div>
 <div class="leftContent">
 左側(cè)劃出
 </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>

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持億速云!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI