入式菜单添加过渡效果

入式菜单添加过渡效果

如何为推入式菜单添加过渡效果?我尝试使用document.getElementById('content')。style.transition =“ left 1.5s”;但它不起作用。我希望得到一些帮助。.我是JS的初学者。



//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> &#8249</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>
  &#9776
 </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>

最佳答案

在CSS中将事务属性用于隐藏的div

-webkit-transition: 2s; /* for Safari browser */
transition: 2s;


它将显示所有变化(包括颜色变化)的平滑运动

关于javascript - 如何在JavaScript中为插入式菜单添加过渡效果?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39242341/

10-12 00:00