Как я могу добавить эффект перехода в меню с кнопками? Я попытался использовать document.getElementById ('content'). Style.transition = "left 1.5s"; но он не работает. Я приветствую какую-то помощь. Я новичок в JS.Как добавить эффект перехода в javascript для push-side menu?
//Javascript for showing the hidden menu
document.getElementById("showMenu").addEventListener("click", menuShow);
function menuShow()
{
document.getElementById('content').style.left = "20%";
document.getElementById('content').style.opacity = "0.6";
document.getElementById("content").style.transition = "opacity 2s";
};
//Javascript for hiding menu
document.getElementById("hideMenu").addEventListener("click", menuHide);
function menuHide()
{
document.getElementById('content').style.left = "0";
document.getElementById('content').style.opacity = "1";
document.getElementById("content").style.transition = "none";
};
body
{
position: relative;
margin: 0;
}
/*Style for the fixed header and show menu button*/
#header
{
width: 100%;
height: 60px;
background-color: grey;
position: fixed;
top: 0;
z-index: 1;
}
#showMenu
{
height: 50px;
width: 50px;
text-align: center;
background-color: transparent;
border-radius: 5px;
position: absolute;
left: 40px;
top: 5px;
line-height: 0.2px;
font-size: 50px;
border: none;
}
#showMenu:hover
{
cursor: pointer;
}
/*Style for the content div*/
#content
{
height: 768px;
width: 100%;
background-color: #0B243B;
position: absolute;
top: 0px;
left: 0%;
-webkit-box-shadow: -7px 0px 15px 0px rgba(0,0,0,0.75);
-moz-box-shadow: -7px 0px 15px 0px rgba(0,0,0,0.75);
box-shadow: -7px 0px 15px 0px rgba(0,0,0,0.75);
text-align: center;
color: white;
}
p
{
width: 50%;
margin: 0 auto;
position: relative;
top: 100px;
text-align: justify;
font-size: 20px;
font-family: calibri;
text-indent: 50px;
}
/*Style for the hidden menu div and hide menu button*/
#hiddenMenu
{
height: 765px;
width: 20%;
background-color: grey;
position: fixed;
}
#hideMenu
{
height: 50px;
width: 50px;
background-color: white;
border-radius: 3px;
position: absolute;
right: 30px;
top: -25px;
font-family: calibri;
border: none;
background-color: transparent;
font-size: 80px;
}
#hideMenu:hover
{
cursor: pointer;
color: white;
}
/*Style for the hidden menu links*/
#hiddenMenu ul li
{
list-style-type: none;
font-family: calibri;
font-size: 20px;
position: relative;
top: 100px;
margin-top: 10px;
margin-left: 20px;
border-top: 1px solid black;
width: 100px;
padding-left: 10px;
}
#hiddenMenu ul li:hover
{
color: white;
cursor: pointer;
}
<div id=hiddenMenu>
<button id=hideMenu> ‹</button>
<ul>
<li><a>About </a></li>
<li><a> Home </a></li>
<li><a> Gallery </a></li>
<li><a> Contact </a></li>
</ul>
</div>
<div id=content>
<div id=header>
<button id=showMenu>
☰
</button>
</div>
<p>
Where does it come from?
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. </p>
<p>The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
</p>
</div>