從螢屏上下左右滑入滑出效果,代碼比較粗糙,但是效果已實作
需要注意的是,從螢屏右邊和下邊滑入的時候,需要給滑動的容器外面再加一個容器,加樣式 position: fixed; 讓它 固定定位,否則頁面右邊和底部會出現滾動條
主要使用了 css animate 屬性
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>JS 螢屏滑入滑出</title> <style> .Left { width: 250px; border: 1px dashed red; background-color: aquamarine; position: absolute; transition: all 1s; left: -260px; top: 400px; } .Right { width: 250px; border: 1px dashed red; background-color: aquamarine; position: absolute; transition: all 1s; right: -260px; top: 400px; } #main { width: 100%; position: fixed; } #up { width: 250px; border: 1px dashed red; background-color: aquamarine; position: absolute; transition: all 1s; top: -144px; left: 600px; } #down { width: 250px; border: 1px dashed red; background-color: aquamarine; position: absolute; transition: all 1s; bottom: -173px; left: 600px; } #mainDown { position: fixed; bottom: 0; } </style> <script src="js/jquery.min.js"></script> </head> <body> <input type="button" value="滑出" style=" width: 85px; height: 33px;" onclick="btnOut();" /> <input type="button" value="滑入" style=" width: 85px; height: 33px;" onclick="btnIn();" /> <div class="Left"> <ul> <li>左邊串列</li> <li>左邊串列</li> <li>左邊串列</li> <li>左邊串列</li> </ul> <span onclick="btnIn();">關閉</span> </div> <div id="main"> <div class="Right"> <ul> <li>右邊串列</li> <li>右邊串列</li> <li>右邊串列</li> <li>右邊串列</li> </ul> <span onclick="btnIn();">關閉</span> </div> </div> <div id="up"> <ul> <li>上邊串列</li> <li>上邊串列</li> <li>上邊串列</li> <li>上邊串列</li> </ul> <span onclick="btnIn();">關閉</span> </div> <div id="mainDown"> <div id="down"> <ul> <li>下邊串列</li> <li>下邊串列</li> <li>下邊串列</li> <li>下邊串列</li> </ul> <span onclick="btnIn();">關閉</span> </div> </div> <script> function btnOut() { $(".Left").animate({}, 1500, function () { $(".Left").css({ "left": "100px" }); }); $(".Right").animate({}, 1500, function () { $(".Right").css({ "right": "100px" }); }) $("#up").animate({}, 1500, function () { $("#up").css({ "top": "50px" }); }); $("#down").animate({}, 1500, function () { $("#down").css({ "bottom": "50px" }); }); } function btnIn() { $(".Left").animate({}, 1500, function () { $(".Left").css({ "left": "-260px" }); }); $(".Right").animate({}, 1500, function () { $(".Right").css({ "right": "-260px" }); }) $("#up").animate({}, 1500, function () { $("#up").css({ "top": "-144px" }); }); $("#down").animate({}, 1500, function () { $("#down").css({ "bottom": "-144px" }); }); } </script> </body> </html>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/498850.html
標籤:HTML5
