简体   繁体   中英

jQuery slide div left to right on hover

I'd like to fix this jquery left to right div on hover: 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;
}

For example: http://www.jamieoliver.com/ -> slider previous next arrow on hover (I need that!!)

My problem is when I trying to hover on the ">" (arrow) it is working sliding left to right. But when I hovering again and again and again while animate sliding to 'width:0' and I leave my mouse from the div the animate don't stop and still hovering left to right for X times I hovered on the div. Can anyone solve this how can I fix this problem?

PS: I guess this problem can be solved by .stop() function. How?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM