【问题标题】:CSS Nav Menu Fade Out OFF HoverCSS Nav Menu Fade Out OFF Hover
【发布时间】:2015-08-31 23:34:41
【问题描述】:

我还在学习 CSS 样式,我想实现一个淡入/淡出导航菜单。阅读起来,我能够成功地在悬停时将淡入编码为我想要的效果。现在我在逻辑上受到挑战,似乎无法想出如何编写该菜单以在鼠标不再悬停在该特定类上时淡出。

* {
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  padding: 0;
  margin: 0;
  background-color: grey;
}
body {
  position: fixed;
  font-family: Serif, sans-serif;
  background: white;
  font-size: 62.5%;
  color: black;
}
/*Nav Wrapper*/

#navWrapper {
  width: 1100px;
  position: fixed;
  top: 30px;
  left: 0px;
  right: 0px;
  margin: 0px;
  margin-left: auto;
  margin-right: auto;
}
/*Banner Wrapper*/

.bannerWrap {
  width: 1100px;
  position: fixed;
  left: 0px;
  right: 0px;
  margin: 0px;
  margin-left: auto;
  margin-right: auto;
}
/*Banner Styling*/

.banner {
  border: 1px solid black;
}
/*Main Nav Box Styling*/

.nav {
  position: fixed;
  list-style: none;
  width: 1102px;
  top: 70px;
  margin: 30px auto 0px auto;
  height: 43px;
  padding: 0px 20px 0px 20px;
  background: #323552;
  background: -moz-linear-gradient(top, #323552, #1a1b24);
  background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#323552), to(#1a1b24));
  border: 1px solid #002232;
}
/*Main Nav Button Styling*/

.nav li {
  float: left;
  text-align: center;
  position: relative;
  padding: 4px 10px 4px 10px;
  margin-right: 30px;
  margin-top: 7px;
  border: none;
  background-color: transparent;
}
/*Main Nav Button Styling*/

.nav > li > a {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  color: #EEEEEE;
  display: block;
  outline: 0;
  text-decoration: none;
  text-shadow: 1px 1px 1px #000;
  text-transform: uppercase;
  background-color: transparent;
}
/*Drop Down On Hover Action*/

.nav > li:hover > div {
  display: block;
  left: 0;
  -webkit-animation: fadein .5s;
  /* Safari and Chrome */
  -moz-animation: fadein .5s;
  /* Firefox */
  -ms-animation: fadein .5s;
  /* Internet Explorer */
  -o-animation: fadein .5s;
  /* Opera */
  animation: fadein .5s;
}
/*Drop Down Container*/

.nav > li > div {
  position: fixed;
  right: -1px;
  top: 147px;
  height: 300px;
  display: none;
  padding: 10px 10px;
  box-shadow: 2px 4px 4px rgba(0, 0, 0, 0.4);
  background: #323552;
  background: -moz-linear-gradient(top, #323552, #1a1b24);
  background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#323552), to(#1a1b24));
  overflow: hidden;
}
/*Drop Down*/

.navMain {
  margin: -4px auto;
  position: fixed;
  text-align: left;
  border: 1px solid #777777;
  border-top: none;
  width: 1060px;
  border: 1px solid black;
}
/*Nav Text Styling*/

.dropContent {
  background: transparent;
  color: #b9b9b9;
}
/*Nav Text Styling*/

.nav-titles {
  display: inline-block;
  font-size: 1.2em;
  font-weight: bold;
  text-align: left;
  padding-right: 3px;
  background: transparent;
}
/*Nav Icons Styling*/

.navIcon {
  width: 15px;
  height: 15px;
  background: transparent;
}
/*Nav Sub Menu*/

.navDropLinks {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  display: block;
  padding-bottom: 6px;
  background: transparent;
}
/*Nav Sub Menu Hyper*/

.navDropLinks > a {
  color: black;
  text-decoration: none;
  font-weight: bold;
  background: transparent;
}
/*Nav Sub Menu Left Column*/

.navLeft {
  position: absolute;
  left: 10px;
  width: 330px;
  display: inline-block;
  font-size: 11px;
  text-align: left;
  padding-right: 3px;
  background: transparent;
}
/*Nav Sub Menu Center Column*/

.navCenter {
  position: absolute;
  width: 330px;
  left: 357px;
  font-size: 11px;
  text-align: center;
  background: transparent;
}
/*Nav Sub Menu Right Column*/

.navRight {
  position: absolute;
  right: 10px;
  width: 330px;
  display: inline-block;
  font-size: 11px;
  text-align: center;
  padding-left: 3px;
  background: transparent;
}
/*Nav Sub Menu Focus Images*/

.navImage {
  display: inline-block;
  width: 275px;
  height: 120px;
  background: transparent;
}
/*Alt Nav Sub Menus*/

.navMain1 {
  margin: -4px auto;
  position: fixed;
  text-align: left;
  border: 1px solid #777777;
  border-top: none;
  width: 1060px;
  /* Gradient background */
  background: #F4F4F4;
  background: -moz-linear-gradient(top, #EEEEEE, #BBBBBB);
  background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#EEEEEE), to(#BBBBBB));
  border: 1px solid black;
}
/*Alt Nav Sub Menus*/

.navMain2 {
  margin: -4px auto;
  position: fixed;
  text-align: left;
  border: 1px solid #777777;
  border-top: none;
  width: 1060px;
  /* Gradient background */
  background: #F4F4F4;
  background: -moz-linear-gradient(top, #EEEEEE, #BBBBBB);
  background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#EEEEEE), to(#BBBBBB));
  border: 1px solid black;
}
/*To Line 270: Keyframes for Nav Animation*/

@keyframes fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
/* Firefox */

@-moz-keyframes fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
/* Safari and Chrome */

@-webkit-keyframes fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
/* Internet Explorer */

@-ms-keyframes fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
/* Opera */

@-o-keyframes fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes fadeout {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}
@-moz-keyframes fadeout {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}
@-webkit-keyframes fadeout {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}
@-o-keyframes fadeout {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}
<!--Nav Wrapper-->
<div class="bannerWrap">
  <img class="banner" src="images/general/site/bannerlg.png">
</div>
<div id="navWrapper">
  <ul class="nav">
    <li><a href="#">Final Cut</a>

      <!--Begin Main Div-->
      <div class="navMain">
        <!--Begin Sub Nav-->
        <div class="navLeft"> <span class="nav-titles">DBZ Final Cut: Navi</span>
          <br>
          <br>
          <br>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> Home</a>
          </div>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> Archived News</a>
          </div>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> About Us</a>
          </div>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> Contact Us</a>
          </div>
          <br>
          <br><span class="dropContent">This is some random text that is describing the current article. The picture above will relate to the article. This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.</span>

        </div>
        <!--End Sub Nav-->
        <!--Begin Nav Center-->
        <div class="navCenter"> <span class="nav-titles">Latest News</span>
          <br>
          <img class="navImage" src="images/general/setsellsheets/mc.jpg" alt="article image" />
          <br> <span class="dropContent">This is some random text that is describing the current article. The picture above will relate to the article. This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                </span>

        </div>
        <!--End of Nav Center-->
        <!--Begin Nav Right-->
        <div class="navRight"> <span class="nav-titles">Latest News</span>
          <br>
          <img class="navImage" src="images/general/setsellsheets/mc.jpg" alt="article image" />
          <br> <span class="dropContent">This is some random text that is describing the current article. The picture above will relate to the article. This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                </span>

        </div>
        <!--End Nave Right-->
      </div>
      <!--End Main Div-->
    </li>
    <li><a href="#">News</a>

      <!--Begin Main Div-->
      <div class="navMain1">
        <!--Begin Sub Nav-->
        <div class="navLeft"> <span class="nav-titles">DBZ Final Cut: Navi</span>
          <br>
          <br>
          <br>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> Home</a>
          </div>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> Archived News</a>
          </div>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> About Us</a>
          </div>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> Contact Us</a>
          </div>
          <br>
          <br><span class="dropContent">This is some random text that is describing the current article. The picture above will relate to the article. This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.</span>

        </div>
        <!--End Sub Nav-->
        <!--Begin Nav Center-->
        <div class="navCenter"> <span class="nav-titles">Latest News</span>
          <br>
          <img class="navImage" src="images/general/setsellsheets/mc.jpg" alt="article image" />
          <br> <span class="dropContent">This is some random text that is describing the current article. The picture above will relate to the article. This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                </span>

        </div>
        <!--End of Nav Center-->
        <!--Begin Nav Right-->
        <div class="navRight"> <span class="nav-titles">Latest News</span>
          <br>
          <img class="navImage" src="images/general/setsellsheets/mc.jpg" alt="article image" />
          <br> <span class="dropContent">This is some random text that is describing the current article. The picture above will relate to the article. This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                </span>

        </div>
        <!--End Nav Right-->
        <!--End Main Div-->
    </li>
    <li><a href="#">Articles</a>

      <!--Begin Main Div-->
      <div class="navMain2">
        <!--Begin Sub Nav-->
        <div class="navLeft"> <span class="nav-titles">DBZ Final Cut: Navi</span>
          <br>
          <br>
          <br>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> Home</a>
          </div>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> Archived News</a>
          </div>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> About Us</a>
          </div>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> Contact Us</a>
          </div>
          <br>
          <br><span class="dropContent">This is some random text that is describing the current article. The picture above will relate to the article. This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.</span>

        </div>
        <!--End Sub Nav-->
        <!--Begin Nav Center-->
        <div class="navCenter"> <span class="nav-titles">Latest News</span>
          <br>
          <img class="navImage" src="images/general/setsellsheets/mc.jpg" alt="article image" />
          <br> <span class="dropContent">This is some random text that is describing the current article. The picture above will relate to the article. This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                </span>

        </div>
        <!--End of Nav Center-->
        <!--Begin Nav Right-->
        <div class="navRight"> <span class="nav-titles">Latest News</span>
          <br>
          <img class="navImage" src="images/general/setsellsheets/mc.jpg" alt="article image" />
          <br> <span class="dropContent">This is some random text that is describing the current article. The picture above will relate to the article. This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                </span>

        </div>
        <!--End Nav Right-->
        <!--End Main Div-->
    </li>
    <li><a href="#">Sets</a>

      <!--Begin Main Div-->
      <div class="navMain1">
        <!--Begin Sub Nav-->
        <div class="navLeft"> <span class="nav-titles">DBZ Final Cut: Navi</span>
          <br>
          <br>
          <br>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> Home</a>
          </div>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> Archived News</a>
          </div>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> About Us</a>
          </div>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> Contact Us</a>
          </div>
          <br>
          <br><span class="dropContent">This is some random text that is describing the current article. The picture above will relate to the article. This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.</span>

        </div>
        <!--End Sub Nav-->
        <!--Begin Nav Center-->
        <div class="navCenter"> <span class="nav-titles">Latest News</span>
          <br>
          <img class="navImage" src="images/general/setsellsheets/mc.jpg" alt="article image" />
          <br> <span class="dropContent">This is some random text that is describing the current article. The picture above will relate to the article. This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                </span>

        </div>
        <!--End of Nav Center-->
        <!--Begin Nav Right-->
        <div class="navRight"> <span class="nav-titles">Latest News</span>
          <br>
          <img class="navImage" src="images/general/setsellsheets/mc.jpg" alt="article image" />
          <br> <span class="dropContent">This is some random text that is describing the current article. The picture above will relate to the article. This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                </span>

        </div>
        <!--End Nav Right-->
        <!--End Main Div-->
    </li>
    <li><a href="#">Resources</a>

      <!--Begin Main Div-->
      <div class="navMain1">
        <!--Begin Sub Nav-->
        <div class="navLeft"> <span class="nav-titles">DBZ Final Cut: Navi</span>
          <br>
          <br>
          <br>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> Home</a>
          </div>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> Archived News</a>
          </div>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> About Us</a>
          </div>
          <div class="navDropLinks">
            <img class="navIcon" src="images/general/site/4staricon.png"><a href="#"> Contact Us</a>
          </div>
          <br>
          <br><span class="dropContent">This is some random text that is describing the current article. The picture above will relate to the article. This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.</span>

        </div>
        <!--End Sub Nav-->
        <!--Begin Nav Center-->
        <div class="navCenter"> <span class="nav-titles">Latest News</span>
          <br>
          <img class="navImage" src="images/general/setsellsheets/mc.jpg" alt="article image" />
          <br> <span class="dropContent">This is some random text that is describing the current article. The picture above will relate to the article. This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                </span>

        </div>
        <!--End of Nav Center-->
        <!--Begin Nav Right-->
        <div class="navRight"> <span class="nav-titles">Latest News</span>
          <br>
          <img class="navImage" src="images/general/setsellsheets/mc.jpg" alt="article image" />
          <br> <span class="dropContent">This is some random text that is describing the current article. The picture above will relate to the article. This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.This is filler text.
                </span>

        </div>
        <!--End Nav Right-->
        <!--End Main Div-->
    </li>
  </ul>
  <!--End Nav List-->
  </div>

Fiddle

我只想要一个简单的淡出效果,希望不必过多地改变我的结构并保持 CSS。

感谢您的帮助!

【问题讨论】:

标签: html css navbar


【解决方案1】:

您可以仅使用过渡来实现良好的淡入/淡出效果。我就是这样做的

.sub-menu {
    position: absolute;
    left: -9999em;
    width: 200px;
    background-color: #eee;
    opacity: 0;
    transition: left 0.5s ease 0.5s, opacity 0.5s ease; /* Transition on left position */
}
.main-nav li:hover .sub-menu {
    left: 0;
    opacity: 1;
    transition: opacity 0.5s ease; /* No transition on left position when hovering */
}

如果您使用left: -9999em 将子菜单放置在屏幕外,然后在该属性上应用过渡延迟,使其首先淡出,然后在不可见时移出屏幕。

但是当悬停状态被激活时,您需要放置另一个转换来覆盖它。这将阻止位置属性在悬停时动画

看看这个jsFiddle

【讨论】:

    【解决方案2】:

    Natalie 是绝对正确的,过渡是这样做的方法。

    唯一需要更改的是 /*Drop Down Container*//*Drop Down On Hover Action*/ 的 CSS

    不要使用display: none; 隐藏div,而是使用opacity: 0; 隐藏它们,然后设置不透明度过渡。 显示它们所需要做的就是将opacity: 1; 置于悬停状态,它们会很好地淡入淡出。

    为了让它们在鼠标经过菜单下方时不会出现,您需要将它们的高度、内边距和边框设置为 0,然后将它们作为悬停状态的一部分应用。

    (如果需要不同的边框样式,可以使用 .navMain、.navMain1 等的单独悬停)

    当然你也可以去掉底部的所有关键帧。

    新的 CSS:

    /*Drop Down On Hover Action*/
    
    .nav > li:hover > div {
        opacity: 1;
        height: 300px;
        padding: 10px 10px;
        border:1px solid #777777; // removed borders from .navMain, .navMain1 etc
        border: 1px solid black;
    }
    
    /*Drop Down Container*/
    
    .nav > li > div {
        position: fixed;
        left: 0;        // added the left: 0; here
        top: 337px;
        height: 0;  // height: 0 when not hovered
        opacity: 0;             // swapped for display:none;
        box-shadow: 2px 4px 4px rgba(0, 0, 0, 0.4);
        background: #323552;
        background: -moz-linear-gradient(top, #323552, #1a1b24);
        background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#323552), to(#1a1b24));
        overflow: hidden;
        -webkit-transition: opacity .5s ease-in-out; 
        -moz-transition: opacity .5s ease-in-out;
        -ms-transition: opacity .5s  ease-in-out;
        -o-transition: opacity .5s ease-in-out;
        transition: opacity .5s ease-in-out;
    }
    

    Updated Fiddle

    【讨论】:

    • 您应该将.nav &gt; li:hover &gt; di 更改为.nav &gt; li a:hover + div 以避免在将鼠标放在菜单下方时显示 div :)
    • 问题在于您实际上无法使用 div,移动菜单的鼠标使其淡出。我将 div 高度移到悬停位置并正常将其高度设为 0 - 现在唯一的问题是向下移动时会闪烁。
    • 找到闪烁的原因 - 当您从 li 向下移动到 div 时,它会停止显示您正在查看的 div,而是始终显示最后一个 div。这似乎是因为尽管height: 0; div 的实际高度仍然为 22px;
    • 这可以通过向悬停状态添加填充和边框来修复 - 编辑答案
    • 这个答案非常有用!感谢那!我希望你能对高度属性有更多的了解。当在悬停动作和下拉容器上设置高度时,淡入淡出效果很好,但存在@NatalieHedström 所指的问题。我相信我听懂了你的意思,但我遇到的问题是淡出会留下一条长长的黑线,而不是实际的菜单,这可能是你指的闪烁?此外,查看更新后的小提琴,该代码似乎不会在演示窗格中淡出。
    【解决方案3】:

    继杰克逊的回答之后,下面是使用转换延迟来实现效果的示例。

    此方法在某些方面更简单,因为您不必将所有填充/边框设置移动到悬停状态。相反,当未悬停时,您将 div 移到远离左侧的位置,然后在悬停状态下设置 left: 0;

    必须设置两次转换(一次用于悬停,一次用于关闭),因为您希望 left: 0; 在悬停时立即生效,并等到不透明度转换后再移回。

    转换的完整语法是transition: &lt;property&gt; &lt;duration&gt; &lt;style: ease&gt; &lt;delay: 0s&gt;

    /*Drop Down On Hover Action*/
    
    .nav > li:hover > div {
        opacity: 1;
        left: 0;
        -webkit-transition: opacity .5s ease-in-out; 
        -moz-transition: opacity .5s ease-in-out;
        -ms-transition: opacity .5s  ease-in-out;
        -o-transition: opacity .5s ease-in-out;
        transition: opacity .5s ease-in-out;
    }
    
    /*Drop Down Container*/
    
    .nav > li > div {
        position: fixed;
        left: -9999em; 
        top: 337px;
        opacity: 0;     
        box-shadow: 2px 4px 4px rgba(0, 0, 0, 0.4);
        background: #323552;
        background: -moz-linear-gradient(top, #323552, #1a1b24);
        background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#323552), to(#1a1b24));
        overflow: hidden;
        -webkit-transition: opacity .5s ease-in-out, left .5s ease .5s; 
        -moz-transition: opacity .5s ease-in-out, left .5s ease .5s;
        -ms-transition: opacity .5s  ease-in-out, left .5s ease .5s;
        -o-transition: opacity .5s ease-in-out, left .5s ease .5s;
        transition: opacity .5s ease-in-out, left .5s ease .5s;
    }
    

    Updated Fiddle

    【讨论】:

    • 非常感谢,前几天在玩了很多之后,我能够使用这种确切的方法让它做我想做的事情。不用麻烦,但是您是否碰巧知道在对淡出应用延迟后可以看到导航主 div 的解决方案?左边的 -9999em 是因为它在转换时移动的原因。我的理论是,实现这一目标的唯一方法是增加它离开屏幕的时间。
    • 我不完全确定您遇到的问题是什么?你能澄清一下吗?
    • 嗯,我会尽力的。我了解您是否无法/不想弄清楚,因为您已经提供了很多帮助。基本上我试图在悬停属性上设置 0.5 秒的转换延迟,这样当鼠标离开主下拉菜单时它不会立即消失(以防用户没有意识到/无意将鼠标移开)。当我在我的 CSS 代码中实现这一点时,会有一个简短的轻弹,类似于您正在最小化向左移动的下拉菜单的窗口(这是由于 Left: -9999em; 标记)。
    • 如果您在不透明度上设置了 0.5 秒的延迟,您需要在左侧延迟中添加 0.5 秒以保持及时。它对我有用:Fiddle
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-26
    • 1970-01-01
    相关资源
    最近更新 更多