javascript - js滑动菜单求助——中间有动画延迟?

标签 javascript jquery css

我正在寻找一个具有某种特定功能的菜单。我对 javascript 和 jquery 比较陌生,所以我不知道从哪里开始。这是我想要它做的事情:

js problem

将鼠标悬停在链接 4 和 5 上也会继续使它们保持最终动画状态。

有什么建议吗?我尝试使用 CSS3 动画执行此操作,但在用户停止将鼠标悬停在链接 3 上然后滑回之前,我无法让它暂停。我还遇到了链接 3 和链接 4 之间的间隙导致悬停停止的问题。 Javascript 似乎是更好的选择。

jsfiddle of my css3 animations

这是包含我的 css3 动画的相关代码:

 -webkit-transition: all .2s ease 0s;
 -moz-transition: all .2s ease 0s;
 -o-transition: all .2s ease 0s;
 -ms-transition: all .2s ease 0s;
 transition: all .2s ease 0s;

编辑:我已经用我当前的 CSS3 动画的 jsfiddle 更新了它(在 jsfiddle 上的实时预览中看起来与我的网站上的有点不同)。

最佳答案

顶部菜单的第三个“li”的宽度已扩展,因此当您将光标移至“额外链接”菜单时,后者不会滑出 View 。

纯 CSS 解决方案:Jsfiddle Link

CSS:

* {
    padding:0;
    margin:0;
}
.links {
    width:100%;
}

.links > menu {
    left: 0%;
    text-align:center;
    position: fixed;
    z-index: 4;
}

.links menu li  {
    whitespace: nowrap;
    display: inline-block;
    margin-right: 30px;
    position: relative;
    padding: 0;
    height: 40px;
    top: 24px;
    z-index: 4;
    float:left;
}

.links a, a:visited {
    font-family: RobotoLight;
    text-decoration: none;
    text-transformation: none;
    weight: normal;
    font-size: 18px;
    color: #000000;
    z-index: 4;
    float:left;
    height: 100%;
}

.links a:hover {
    font-family: RobotoLight;
    text-decoration: none;
    text-transformation: none;
    weight: normal;
    font-size: 18px;
    color: #33b5e5;
    z-index: 4;
}

.l3 .extralinks {
    white-space: nowrap;
    position: fixed;
    top: 0px;
    left:100%;
    padding: 0 0 0 10px;
    text-align:center;
    height: 40px;
    width: 300px;
    z-index: 4;
    display: inline-block;
    -webkit-transition: all .2s ease 0s;
    -moz-transition: all .2s ease 0s;
    -o-transition: all .2s ease 0s;
    -ms-transition: all .2s ease 0s;
    transition: all .2s ease 0s;
    z-index: 4;
}
.l3:hover .extralinks {
    left: 50%;    
}
.l3:hover .extralinks li {
}


.links li:nth-child(3) {
    width:200px;
    margin-right:0px;
}

.links li:nth-child(3):hover > a {
    font-family: RobotoLight;
    text-decoration: none;
    text-transformation: none;
    weight: normal;
    font-size: 18px;
    color: #33b5e5;
    z-index: 4;                
    border-bottom: 3px solid #33b5e5;
}


.links li:hover > a, li:active > a {
    border-bottom: 3px solid #33b5e5;
}  

HTML:

<div class="links">
    <menu>
        <li>
            <a href="#">Link 1</a>
        </li>
        <li>
            <a href="#">Link 2</a>
        </li>
        <li class="l3">
            <a href="#">Link 3</a>
            <menu class="extralinks">
                <li>
                    <a href="#">Link 4</a>
                </li>
                <li>
                    <a href="#">Link 5</a>
                </li>
            </menu>
        </li>
    </menu>
</div>

关于javascript - js滑动菜单求助——中间有动画延迟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16076883/

相关文章:

javascript - 如何实现 stickyfloat.js?

javascript - 使用 anchor 将 href 链接到下一个 div

javascript - 为什么我的函数不会改变对象值?

javascript - 如何检查属性值是否等于oue值并获取该元素中另一个属性的值?

jQuery,.each() 问题

javascript - 取消选择 radio 输入选择

javascript - 如何在 InnerHTML 函数中输出 jquery 代码?

javascript - 使用自定义选项编写Vue插件

javascript - 组件/集成测试主干 View 等

javascript - 如何从 jQuery 选择器中获取 DOM 元素?