嗨,大家好我试图让右上角固定的导航来自屏幕的右侧(从右到左动画)。现在使用w3school的示例我能够得到以下代码: HTML:
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="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" onclick="openNav()">☰</span>
SCSS:
#mySidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
padding-top: 60px;
transition: 0.5s;
a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
transition: 0.3s
}
a:hover, .offcanvas a:focus{
color: #f1f1f1;
}
.closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 55px;
margin-left: 50px;
}
JS:
function openNav() {
document.getElementById('mySidenav').style.width = '300px';
}
function closeNav() {
document.getElementById('mySidenav').style.width = '0';
}
现在代码工作正常,而不是我的问题。我想让我的sidenav固定在右上角,动画从右到左,我每次尝试都是彻底失败。所以我的问题是可以做到这一点,你们会怎么做呢???? 这是我制作的codepen的链接,因此您可以看到代码在行动中https://codepen.io/Karadjordje/pen/MpKvXp
答案 0 :(得分:2)
将left: 0;
更改为right: 0;
。
工作示例:
function openNav() {
document.getElementById('mySidenav').style.width = '300px';
}
function closeNav() {
document.getElementById('mySidenav').style.width = '0';
}
&#13;
.hamburger {
font-size: 30px;
cursor: pointer;
top: 20px;
right: 20px;
position: fixed;
}
#mySidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
right: 0;
background-color: #111;
overflow-x: hidden;
padding-top: 60px;
transition: 0.5s;
}
#mySidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
transition: 0.3s
}
#mySidenav a:hover,
#mySidenav .offcanvas a:focus {
color: #f1f1f1;
}
#mySidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 55px;
margin-left: 50px;
}
body {
height: 200em;
position: relative;
}
&#13;
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Clients</a>
<a href="#">Contact</a>
</div>
<span class="hamburger" onclick="openNav()">☰</span>
&#13;