我已经在 codepen 中看到此代码作为示例,因此我尝试将其复制到我在 phpstorm 中的项目中。我运行代码,但侧边栏没有向我打开,我不明白为什么。这是代码:
<!DOCTYPE html>
<html>
<head>
<link rel = "stylesheet" type="text/css" href = "Sources/bootstrap.css">
<link rel = "stylesheet" type="text/css" href = "Sources/MatirialIcons.css">
<link rel = "stylesheet" type="text/css" href = "Sources/Matirialize.css">
<script type = "text/javascript"
src = "Sources/jquery-2.1.1.js"></script>
<script src = "Sources/Matirialize.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<style>
body {
font-family: "Lato", sans-serif;
}
.sidenav {
height: 100%;
width: 250px;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
transition: 0.5s;
transform: translateX(-100%);
padding-top: 60px;
}
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
transition: 0.3s;
}
.sidenav a:hover {
color: #f1f1f1;
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
.open-bg {
background-color: rgba(0,0,0,0.4);
overflow: hidden;
}
.open {
transform: translateX(0px);
}
@media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
</style>
<body>
<div class="container">
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" id="closeNav">×</a>
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Clients</a>
<a href="#">Contact</a>
</div>
<span style="font-size:30px;cursor:pointer" id="openNav">☰ Brand</span>
</div>
</body>
<script>
$( "#openNav" ).click(function() {
$('#mySidenav').addClass('open');
$('body').addClass('open-bg');
});
$( "#closeNav" ).click(function() {
$('#mySidenav').removeClass('open');
$('body').removeClass('open-bg');
});
</script>
</html>
为什么侧边栏打不开?这是我从中复制的 codepen 代码的链接: https ://codepen.io/shantikumarsingh/pen/gXPjdG
它在那里完美运行,我需要一个与示例中完全相同的侧边栏。