【问题标题】:jQuery slide div left to right on hover悬停时jQuery从左到右滑动div
【发布时间】:2014-03-10 14:47:15
【问题描述】:

我想在悬停时从左到右修复这个 jquery:http://jsfiddle.net/PXLJG

HTML:

<div class="holdingbox">
<span class="rightbox">
    <span class="content">Kenyér</span>
</span>
<span class="leftbox">></span>

jQuery:

$('.holdingbox').hover(function(){
    $('.rightbox').animate({width: '90px'}, 1000)
}, function(){
    $('.rightbox').animate({width: '-0'}, 1000)
});

CSS:

div {
    display : inline-block;
}
.holdingbox {
    position: relative;
    top: 0;
    margin-left: 100px;
}

.leftbox {
    position: relative;
    top: 0;
    left: 0;
    display: inline-block;
    font-size: 24px;
    background-color: #ac193d;
    color: #FFF;
    font-weight: bold;
    padding: 1px;
}
.rightbox {
    position: relative;
    display: inline-block;
    overflow: hidden;
    width: 0;
    height: 30px;
    vertical-align: top;
    margin-right: 0;
}
.content{
    width: 100px;
    position: absolute;
    background-color: #ac193d;
    height: 29px;
    left: 0;
    top: 0;
    right: 0;
    color: #FFF;
    padding-left: 5px;
}

例如:http://www.jamieoliver.com/ -> 悬停时滑块上一个下一个箭头(我需要那个!!)

我的问题是当我试图将鼠标悬停在“>”(箭头)上时,它正在从左向右滑动。但是,当我在动画滑动到“宽度:0”时一次又一次地悬停并且我将鼠标从 div 上移开时,动画不会停止并且仍然从左到右悬停 X 次,我悬停在 div 上。任何人都可以解决这个问题,我该如何解决这个问题?

P.S.:我想这个问题可以通过 .stop() 函数来解决。怎么样?

【问题讨论】:

  • 太棒了,您已将 fiddle 格式化为代码以绕过 指向 jsfiddle 的链接应包含代码。你不认为这个错误是有原因的吗? IE。 jsfiddle 的链接也应该包含代码?

标签: javascript jquery css


【解决方案1】:

您可以使用 .stop() 来停止当前动画: http://jsfiddle.net/PXLJG/2/

$('.rightbox').stop().animate({width: '-0'}, 1000)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-07
    相关资源
    最近更新 更多