<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0"> <style> *{margin:0;padding:0;} body { overflow-x: hidden; width: 320px; } #nav { position: fixed; left: -100px; top: 0; width: 100px; height: 100%; background: #f90; } #content { margin: 0 auto; width: 320px; height: 3000px; background: #666; } .showNav { transform: translateX(100px); -webkit-transform: translateX(100px); transition: transform 1s; -webkit-transition: -webkit-transform 1s; } </style> </head> <body> <div id="nav"></div> <div id="content"> <input type="button" value="点我试试" id="btn"> </div> <script> var oBtn = document.getElementById("btn"); oBtn.onclick = function() { document.body.className = "showNav"; } </script> </body> </html>
手机端左侧固定导航栏推出效果