Side navigation bar settings.

huangapple go评论70阅读模式
英文:

Settings of side navigation bar

问题

I'm trying to change the visibility of side navigation bar.

Currently,
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>

when the cross mark (&times) is clicked, the side navigation bar completely hides. I want it to be partially visible, like the one below.

Side navigation bar settings.

I tried to change the style option left: -20px;, but this doesn't help.

.sidenav {
    height: 100%;
    width: 250px;
    position: fixed;
    z-index: 3;
    top: 80px;
    left: 0px;
    background-color: #111;
    overflow-x: hidden;
    transition: 0.5s;
    padding-top: 60px;
}

.open .sidenav {
    left: -20px;
}

Complete code

{% load static %}
<html>
    <head>
        <!-- ... (略) ... -->
        <style>
            <!-- ... () ... -->
            .sidenav {
                height: 100%;
                width: 250px;
                position: fixed;
                z-index: 3;
                top: 80px;
                left: 0px;
                background-color: #111;
                overflow-x: hidden;
                transition: 0.5s;
                padding-top: 60px;
            }

            .open .sidenav {
                left: -20px;
            }

            <!-- ... () ... -->
        </style>
    </head>
    <body>
        <!-- ... (略) ... -->
    </body>
</html>

Suggestions on how to make the side navigation bar partially visible will be really helpful.

Also, to open and close the side navigation bar, I included an arrow

<div class="left-arrow" onclick="toggleNav()"></div>

But this is not working on click, i.e., I cannot close or open the side nav. by clicking the small arrow.

Side navigation bar settings.

Suggestions on how to fix these issues will be really helpful.

英文:

I'm trying to change the visibility of side navigation bar.

Currently,
&lt;a href=&quot;javascript:void(0)&quot; class=&quot;closebtn&quot; onclick=&quot;closeNav()&quot;&gt;&amp;times;&lt;/a&gt;

when the cross mark (&times) is clicked, the side navigation bar completely hides. I want it to be partially visible, like the one below.

Side navigation bar settings.

I tried to change the style option left: -20px;, but this doesn't help.

.sidenav {
              height: 100%;
              width: 250px;
              position: fixed;
              z-index: 3;
              top: 80px;
              left: 0px;
              background-color: #111;
              overflow-x: hidden;
              transition: 0.5s;
              padding-top: 60px;
            }

Complete code

{% load static %}
&lt;html&gt;
&lt;head&gt;
&lt;nav class=&quot;nav&quot;&gt;
&lt;ul class=&quot;nav__links&quot;&gt;
&lt;li class=&quot;nav__item&quot;&gt;
&lt;a class=&quot;nav__link&quot; href=&quot;{% url &#39;home&#39; %}&quot;&gt;Home&lt;/a&gt;
&lt;/li&gt;
&lt;li class=&quot;nav__item&quot;&gt;
&lt;a class=&quot;nav__link&quot; href=&quot;{% url &#39;about&#39; %}&quot;&gt;About&lt;/a&gt;
&lt;/li&gt;
&lt;li class=&quot;nav__item&quot;&gt;
&lt;a class=&quot;nav__link&quot; href=&quot;{% url &#39;login&#39; %}&quot;&gt;Login&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/nav&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
&lt;title&gt;
Visualization
&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;
&lt;script src=&quot;https://cdn.plot.ly/plotly-1.58.5.min.js&quot;&gt;&lt;/script&gt;
&lt;style&gt;
.graph-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.main-panel {
width: 100%;
height: 800px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.side-panel {
position: absolute;
top: 0px;
bottom: 0;
right: -300px;
width: 300px;
background-color: red;
transition: right 0.5s;
overflow-y: auto;
padding: 20px;
}
.side-panel.open {
right: 0;
}
.arrow {
position: absolute;
top: 20px;
left: 20px;
width: 0;
height: 0;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
border-right: 20px solid #2196F3;
cursor: pointer;
}
.arrow.open {
transform: rotate(180deg);
}
.left-arrow {
position: absolute;
top: 20px;
right: 20px;
width: 0;
height: 0;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
border-right: 20px solid #2196F3;
cursor: pointer;
}
.open .left-arrow {
transform: rotate(180deg);
}
{# Added Code for side bar  #}
.sidenav {
height: 100%;
width: 250px;
position: fixed;
z-index: 3;
top: 80px;
left: 0px;
background-color: #111;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
}
.open .sidenav {
left: -20px;
}
.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;
}
#main {
transition: margin-left .5s;
padding: 16px;
margin-left: 250px;
}
.form {
border-radius: 20px;
box-sizing: border-box;
height: 500px;
padding: 20px;
width: inherit;
font-size: 1.8rem;
}
.title{
color: #eee;
font-family: &quot;Bitstream Vera Sans Mono&quot;, Monaco, &quot;Courier New&quot;, Courier, monospace;
font-size: 25px;
font-weight: 400;
padding-left: 15px;
}
.input-container {
height: 50px;
position: relative;
width: 100%;
}
.soura {
margin-top: 40px;
}
.ic2 {
margin-top: 30px;
}
.input {
background-color: #303245;
border-radius: 12px;
border: 0;
box-sizing: border-box;
color: #eee;
font-size: 18px;
height: 100%;
outline: 0;
padding: 4px 20px 0;
width: 100%;
}
.cut {
background-color: black;
border-radius: 10px;
height: 20px;
left: 20px;
position: absolute;
top: -20px;
transform: translateY(0);
transition: transform 200ms;
}
.arrowsize-cut{
width: 80px;
}
.concentration-cut{
width: 105px;
}
.example-cut{
width: 140px;
}
.labelsize-cut{
width: 80px;
}
.input:focus ~ .cut,
.input:not(:placeholder-shown) ~ .cut {
transform: translateY(8px);
}
.placeholder {
color: #65657b;
font-family: sans-serif;
left: 20px;
line-height: 14px;
position: absolute;
transform-origin: 0 50%;
transition: transform 200ms, color 200ms;
top: 20px;
}
.input:focus ~ .placeholder,
.input:not(:placeholder-shown) ~ .placeholder {
transform: translateY(-30px) translateX(10px) scale(0.75);
}
.input:not(:placeholder-shown) ~ .placeholder {
color: #808097;
}
.input:focus ~ .placeholder {
color: #dc2f55;
}
.submit {
background-color: #08d;
border-radius: 12px;
border: 0;
box-sizing: border-box;
color: #eee;
cursor: pointer;
font-size: 18px;
height: 30px;
margin-top: 38px;
outline: 0;
text-align: center;
width: 100%;
}
.submit:active {
background-color: #06b;
}
/* Adding the button */
@media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
/* Code for download button */
.hide {
max-height: 0 !important;
}
.dropdown{
border: 0.1em solid white;
width: 18em;
margin-bottom: 1em;
margin-top: 2rem;
position: relative;
}
.dropdown .title{
margin: .3em .3em .3em .3em;
width: 100%;
}
.dropdown .title .fa-angle-right{
float: right;
margin-right: .7em;
transition: transform .3s;
}
.dropdown .menu{
transition: bottom .5s ease-out;
background-color: black;
min-width: 18rem;
/* bottom: 7.9em; */
border:  solid white;
overflow: hidden;
position: absolute;
font-size: 10px;
}
.dropdown .menu .option{
margin: .1em .1em .1em .1em;
margin-top: 0.3em;
color: white;
font-size: 10px;
}
.dropdown .menu .option:hover{
background: rgba(0,0,0,0.2);
}
.pointerCursor:hover{
cursor: pointer;
}
.rotate-90{
transform: rotate(-90deg);
}
.clickable {
cursor: pointer;
text-decoration: underline;
color: blue;
}
.dropdown .download-button {
position: absolute;
top: 0;
right: -60px; /* Adjust the position as needed */
width: 50px;
height: 100%;
background-color: #333;
border: none;
border-radius: 0 4px 4px 0;
color: white;
font-size: 16px;
cursor: pointer;
}
.dropdown .download-button i {
margin-top: 6px;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id = &quot;main&quot; style=&quot;margin-left: 7rem;&quot;&gt;
&lt;div id=&quot;mySidenav&quot; class=&quot;sidenav&quot;&gt;
&lt;div class=&quot;left-arrow&quot; onclick=&quot;toggleNav()&quot;&gt;&lt;/div&gt;
&lt;a href=&quot;javascript:void(0)&quot; class=&quot;closebtn&quot; onclick=&quot;closeNav()&quot;&gt;&amp;times;&lt;/a&gt;
&lt;form class=&quot;form&quot; id=&quot;myForm&quot; action=&quot;{% url &#39;visualization&#39; %}&quot; method=&quot;post&quot;&gt;
{% csrf_token %}
&lt;div class = &quot;title&quot;&gt;settings&lt;/div&gt;
&lt;div class=&quot;input-container soura&quot;&gt;
&lt;input id=&quot;examples&quot; class=&quot;input&quot; name=&quot;examples&quot; placeholder=&quot; &quot; onfocusout=getExampleValue() /&gt;
&lt;div class=&quot;cut example-cut&quot;&gt;&lt;/div&gt;
&lt;label for=&quot;examples&quot; class=&quot;placeholder&quot;&gt;
Examples
&lt;span id=&quot;example1&quot; class=&quot;example&quot; onclick=&quot;setExampleValue(&#39;example1&#39;)&quot;&gt; #1&lt;/span&gt;
&lt;span id=&quot;example2&quot; class=&quot;example&quot; onclick=&quot;setExampleValue(&#39;example2&#39;)&quot;&gt; #2&lt;/span&gt;
&lt;/label&gt;
&lt;/div&gt;
&lt;div class=&quot;input-container ic2&quot;&gt;
&lt;input id=&quot;arrowsize&quot; class=&quot;input&quot; type=&quot;text&quot; placeholder=&quot; &quot; /&gt;
&lt;div class=&quot;cut arrowsize-cut&quot;&gt;&lt;/div&gt;
&lt;label for=&quot;arrowsize&quot; class=&quot;placeholder&quot;&gt;arrow size&lt;/label&gt;
&lt;/div&gt;
&lt;div class=&quot;input-container ic2&quot;&gt;
&lt;input id=&quot;labelsize&quot; class=&quot;input&quot; type=&quot;text&quot; placeholder=&quot; &quot; /&gt;
&lt;div class=&quot;cut arrowsize-cut&quot;&gt;&lt;/div&gt;
&lt;label for=&quot;labelsize&quot; class=&quot;placeholder&quot;&gt;label font-size&lt;/label&gt;
&lt;/div&gt;
&lt;button type=&quot;submit&quot; class=&quot;submit&quot;&gt;Submit&lt;/button&gt;
&lt;/form&gt;
&lt;div class=&#39;dropdown&#39;&gt;
&lt;a class=&#39;title pointerCursor&#39;&gt;Download &lt;i class=&quot;fa fa-angle-down&quot;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;div class=&#39;menu pointerCursor hide&#39;&gt;
&lt;div class=&#39;option&#39; id=&#39;option1&#39;&gt;&lt;a href=&quot;#&quot;&gt;PNG&lt;/a&gt;&lt;/div&gt;
&lt;div class=&#39;option&#39; id=&#39;option2&#39;&gt;&lt;a href=&quot;#&quot;&gt;SVG&lt;/a&gt;&lt;/div&gt;
&lt;div class=&#39;option&#39; id=&#39;option3&#39;&gt;&lt;a href=&quot;#&quot;&gt;JPEG&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;button class=&quot;download-button&quot;&gt;&lt;i class=&quot;fa fa-download&quot;&gt;&lt;/i&gt;&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;graph-container&quot;&gt;
&lt;div id=&quot;network&quot; class=&quot;main-panel&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;graph&quot; class=&quot;side-panel&quot;&gt;
&lt;div class=&quot;arrow&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;script src=&quot;https://kit.fontawesome.com/adf1f3a283.js&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
&lt;script&gt;
function openNav() {
document.getElementById(&quot;mySidenav&quot;).style.width = &quot;250px&quot;;
//document.getElementById(&quot;mySidenav&quot;).classList.add(&quot;open&quot;);
document.getElementById(&quot;main&quot;).style.marginLeft = &quot;250px&quot;;
}
function closeNav() {
document.getElementById(&quot;mySidenav&quot;).style.width = &quot;0&quot;;
// document.getElementById(&quot;mySidenav&quot;).classList.remove(&quot;open&quot;);
document.getElementById(&quot;main&quot;).style.marginLeft = &quot;0&quot;;
}
// examples
function setExampleValue(value) {
document.getElementById(&quot;examples&quot;).value = value;
}
// download options
const dropdownTitle = document.querySelector(&#39;.dropdown .title&#39;);
const dropdownMenu = document.querySelector(&#39;.dropdown .menu&#39;);
dropdownTitle.addEventListener(&#39;click&#39;, function () {
dropdownMenu.classList.toggle(&#39;hide&#39;);
});
document.querySelectorAll(&#39;.dropdown .option&#39;).forEach(function (option) {
option.addEventListener(&#39;click&#39;, function () {
// Handle the selected download option here
const selectedOption = this.textContent;
console.log(&#39;Selected option:&#39;, selectedOption);
// Display the selected option in the dropdown title
dropdownTitle.textContent = `Download ${selectedOption}`;
// Close the dropdown menu
dropdownMenu.classList.add(&#39;hide&#39;);
});
});
function getExampleValue() {
const fid = document.getElementById(&quot;examples&quot;).value;
console.log(fid)
const fpath = `${fid}.json`;
//read the data from the json file
fetch(fpath)
.then(response =&gt; response.json())
.then(data =&gt; {
var x = data.x
})
}
&lt;/script&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

Suggestions on how to make the side navigation bar partially visible will be really helpful.

Also, to open and close the side navigation bar, I included an arrow

        &lt;div class=&quot;left-arrow&quot; onclick=&quot;toggleNav()&quot;&gt;&lt;/div&gt;

But this is not working on click, i.e., I cannot close or open the side nav. by clicking the small arrow.

Side navigation bar settings.

Suggestions on how to fix these issues will be really helpful.

答案1

得分: 1

在你的 closeNav() 函数中,你将 mySidenav 元素的 width 设置为 0px,这意味着该元素不可见,因此任何像 left: -20px; 这样的操作都不会起作用,因为元素根本不存在(即没有宽度!),所以将 0px 更改为 60px 以使元素部分可见。

function closeNav() {
document.getElementById("mySidenav").style.width = "60px";
}
英文:

In your closeNav() function, you're setting the width of the mySidenav element to 0px which means the element isn't visible, so anything like left: -20px; won't do anything because the element isn't even there (i.e. no width!), so change 0px to 60px to make the element partially visible.

function closeNav() {
document.getElementById(&quot;mySidenav&quot;).style.width = &quot;60px&quot;;
}

答案2

得分: 1

这是您要翻译的内容:

"It does not makes sense to set the width and the position at the same time. So you need to choose the best fit for what you need.

For the openning arrow you can use a variable to keep track of the state of the sidebar (true = opened, false = closed) and call the function openNav/closeNav bassed on that.

let navState = false;
function toggleNav() {
if(navState){
closeNav();
}else{
openNav();
}
navState = !navState;
}
function openNav() {
document.getElementById("mySidenav").classList.add("open");
document.getElementById("main").style.marginLeft = "250px";
}

function closeNav() {
document.getElementById("mySidenav").classList.remove("open");
document.getElementById("main").style.marginLeft = "50px";
}

A implementation setting the position instead of the width: codepen.io"

您可以在这个链接中查看将位置设置而不是宽度的实现:codepen.io

英文:

It does not makes sense to set the width and the position at the same time. So you need to choose the best fit for what you need. <br>
For the openning arrow you can use a variable to keep track of the state of the sidebar (true = opened, false = closed) and call the function openNav/closeNav bassed on that. <br>

let navState = false;
function toggleNav() {
if(navState){
closeNav();
}else{
openNav();
}
navState = !navState;
}
function openNav() {
document.getElementById(&quot;mySidenav&quot;).classList.add(&quot;open&quot;);
document.getElementById(&quot;main&quot;).style.marginLeft = &quot;250px&quot;;
}
function closeNav() {
document.getElementById(&quot;mySidenav&quot;).classList.remove(&quot;open&quot;);
document.getElementById(&quot;main&quot;).style.marginLeft = &quot;50px&quot;;
}

A implementation setting the position instead of the width: codepen.io

huangapple
  • 本文由 发表于 2023年7月5日 01:04:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76614661.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定