关闭功能
Coddy 侧边栏|前端项目 课程的第 12 课,共 13 课。
现在样式已经完成,我们来添加点击功能吧!
挑战
简单在 JavaScript 模块中,定位 id #closeSidebarBtn;点击它后,将 'sidebar' 类的 right 属性设为 -250px。
亲手试试
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<title>Mobile Sidebar</title>
</head>
<body>
<button id="openSidebarBtn">Open</button>
<div id="sidebar" class="sidebar">
<button id="closeSidebarBtn">Close</button>
<!-- 在这里添加侧边栏内容 -->
<p>Home</p>
<p>About</p>
<p>Services</p>
<p>Contact</p>
</div>
<script src="script.js"></script>
</body>
</html>
侧边栏|前端项目中的所有课
自己练习: Web 在线编辑器