JS 从屏幕上下左右滑入滑出效果
从屏幕上下左右滑入滑出效果,代码比较粗糙,但是效果已实现
需要注意的是,从屏幕右边和下边滑入的时候,需要给滑动的容器外面再加一个容器,加样式 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>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix