2017-03-01 75 views
0

嗨,大家好,我試圖讓固定在右上角的導航來自屏幕右側(從右到左的動畫)。現在,使用從w3school我能想出下面的代碼示例: HTML:Sidenav覆蓋固定在右上角

<div id="mySidenav" class="sidenav"> 
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times; </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()">&#9776;</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從右到左固定在右上角,我做的每一個嘗試都是完全失敗的。所以我的問題是有可能做到這一點,你們會怎麼做? 這裏是鏈接到我做,所以你可以看到在行動https://codepen.io/Karadjordje/pen/MpKvXp

+0

這樣嗎?什麼是徹底的失敗?似乎所有你需要做的是將固定菜單的'left'改爲'right',但我也移動了你的漢堡包圖標https://codepen.io/mcoker/pen/MpKEWE –

回答

2

變化left: 0;代碼right: 0;的codepen。

工作例如:

function openNav() { 
 
    document.getElementById('mySidenav').style.width = '300px'; 
 
} 
 

 
function closeNav() { 
 
    document.getElementById('mySidenav').style.width = '0'; 
 
}
.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; 
 
}
<div id="mySidenav" class="sidenav"> 
 
    <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a> 
 
    <a href="#">About</a> 
 
    <a href="#">Services</a> 
 
    <a href="#">Clients</a> 
 
    <a href="#">Contact</a> 
 
</div> 
 
<span class="hamburger" onclick="openNav()">&#9776;</span>

+0

謝謝你的幫助,但我仍然希望我的漢堡總是在屏幕的右上角。如果你瞭解我,請跟隨滾動。 – Zvezdas1989

+0

剛剛對我的代碼進行了更新。你是這個意思嗎? –

+0

部分跨度也應該固定在右上角 – Zvezdas1989