为什么导航菜单滑块按钮不起作用? 我已经包含了Jquery ..任何人都可以指出我的错误吗?
没有jquery cdn的代码示例来自 http://codepen.io/birdsong/pen/DxajG
我如何创建右滑块标签的另一个版本?我觉得它很简单?复制粘贴和更改变量?
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="navContainer">
<ul>
<li>Home</li>
<li>Page 1</li>
<li>Page 2</li>
<li>Page 3</li>
<li>Page 4</li>
<li>Page 5</li>
<li>Page 6</li>
<li>Page 7</li>
</ul>
<div id="contentContainer">
<header>
<div href="" onclick="openNav();" class="button"></div>
</header>
<div id="placeCheckHere"></div>
</div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
function closeNav() {
$('#contentContainer').removeClass('moveOut').addClass('moveIn');
$('#navContainer ul').removeClass('slideIn').addClass('slideOut');
$('#placeCheckHere').html("");
}
function openNav() {
$('#contentContainer').removeClass('moveIn').addClass('moveOut');
$('#navContainer ul').removeClass('slideOut').addClass('slideIn');
$('#placeCheckHere').html("<div id='checkNavDiv' onclick='closeNav();'></div>");
}
</script>
</body>
</html>
答案 0 :(得分:0)
我认为问题在于您尝试重现该示例,但遇到的问题是scss
。
所以这里是示例的完整代码,并且相反地工作(粗略地),
从左到右
<强> CSS 强>
* {
padding: 0;
margin: 0;
}
html, body {
width: 100%;
height: 100%;
}
body {
font-family: 'Helvetica';
font-weight: 300;
}
#navContainer {
width: 85%;
height: 100%;
padding-right: 15%;
display: block;
background: #222;
position: relative;
top: 0px;
left: 0px;
overflow-x: hidden;
z-index: 1;
}
ul {
list-style: none;
padding: 10px;
}
li {
padding: 10px;
color: #eee;
}
#contentContainer {
width: 100%;
min-height: 100%;
position: absolute;
background: #ddd;
z-index: 2;
top: 0px;
left: 0px;
box-shadow: 0 0 40px black;
}
#checkNavDiv {
width: 100%;
height: 100%;
display: block;
position: absolute;
top: 0px;
left: 0px;
cursor: pointer;
}
header {
width: 100%;
height: 50px;
background: #bbb;
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.5);
}
.button {
width: 33px;
height: 24px;
background: url("http://birdsongmedia.com/images/menu-icon1.png");
cursor: pointer;
position: relative;
top: 13px;
left: 19px;
}
article {
padding: 10px;
}
.moveOut {
-webkit-animation: moveContentOut 0.35s ease;
-webkit-transform: translate(85%, 0);
}
.moveIn {
-webkit-animation: moveContentIn 0.35s ease;
-webkit-transform: translate(0, 0);
}
@-webkit-keyframes moveContentOut {
0% {
-webkit-transform: translate(0, 0);
}
100% {
-webkit-transform: translate(85%, 0);
}
}
@-webkit-keyframes moveContentIn {
0% {
-webkit-transform: translate(85%, 0);
}
100% {
-webkit-transform: translate(0, 0);
}
}
.slideIn {
-webkit-animation: navSlideIn 0.35s ease;
-webkit-transform: translate(0, 0);
}
.slideOut {
-webkit-animation: navSlideOut 0.35s ease;
-webkit-transform: translate(-40px, 0);
}
@-webkit-keyframes navSlideIn {
0% {
-webkit-transform: translate(-40px, 0);
}
100% {
-webkit-transform: translate(0, 0);
}
}
@-webkit-keyframes navSlideOut {
0% {
-webkit-transform: translate(0, 0);
}
100% {
-webkit-transform: translate(-40px, 0);
}
}
从右到左
<强> CSS 强>
* {
padding: 0;
margin: 0;
}
html, body {
width: 100%;
height: 100%;
}
body {
font-family: 'Helvetica';
font-weight: 300;
}
#navContainer {
width: 85%;
height: 100%;
padding-right: 15%;
display: block;
background: #222;
position: relative;
top: 0px;
left: 0px;
overflow-x: hidden;
z-index: 1;
}
ul {
list-style: none;
padding: 10px;
}
#navContainer ul {
position: relative;
left: 110%;
}
li {
padding: 10px;
color: #eee;
}
#contentContainer {
width: 100%;
min-height: 100%;
position: absolute;
background: #ddd;
z-index: 2;
top: 0px;
left: 0px;
box-shadow: 0 0 40px black;
}
#checkNavDiv {
width: 100%;
height: 100%;
display: block;
position: absolute;
top: 0px;
left: 0px;
cursor: pointer;
}
header {
width: 100%;
height: 50px;
background: #bbb;
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.5);
}
.button {
width: 33px;
height: 24px;
background: url("http://birdsongmedia.com/images/menu-icon1.png");
cursor: pointer;
position: relative;
top: 13px;
left: -19px;
float: right;
}
article {
padding: 10px;
}
.moveOut {
-webkit-animation: moveContentOut 0.35s ease;
-webkit-transform: translate(-85%, 0);
}
.moveIn {
-webkit-animation: moveContentIn 0.35s ease;
-webkit-transform: translate(0, 0);
}
@-webkit-keyframes moveContentOut {
0% {
-webkit-transform: translate(0, 0);
}
100% {
-webkit-transform: translate(-85%, 0);
}
}
@-webkit-keyframes moveContentIn {
0% {
-webkit-transform: translate(-85%, 0);
}
100% {
-webkit-transform: translate(0, 0);
}
}
.slideIn {
-webkit-animation: navSlideIn 0.35s ease;
-webkit-transform: translate(0, 0);
}
.slideOut {
-webkit-animation: navSlideOut 0.35s ease;
-webkit-transform: translate(-40px, 0);
}
@-webkit-keyframes navSlideIn {
0% {
-webkit-transform: translate(-40px, 0);
}
100% {
-webkit-transform: translate(0, 0);
}
}
@-webkit-keyframes navSlideOut {
0% {
-webkit-transform: translate(0, 0);
}
100% {
-webkit-transform: translate(-40px, 0);
}
}
常见的html和js
<div id="navContainer">
<ul>
<li>Home</li>
<li>Page 1</li>
<li>Page 2</li>
<li>Page 3</li>
<li>Page 4</li>
<li>Page 5</li>
<li>Page 6</li>
<li>Page 7</li>
</ul>
<div id="contentContainer">
<header>
<div href="" onclick="openNav();" class="button"></div>
</header>
<div id="placeCheckHere"></div>
</div>
</div>
<强> JS 强>
function closeNav() {
$('#contentContainer').removeClass('moveOut').addClass('moveIn');
$('#navContainer ul').removeClass('slideIn').addClass('slideOut');
$('#placeCheckHere').html("");
}
function openNav() {
$('#contentContainer').removeClass('moveIn').addClass('moveOut');
$('#navContainer ul').removeClass('slideOut').addClass('slideIn');
$('#placeCheckHere').html("<div id='checkNavDiv' onclick='closeNav();'></div>");
}