jquery问题与mouseenter()+ animate()

用户名

里面一个div .frame我有3人的div: .top.middle.bottom

.top使用jQuery函数时.bottom都在display none,当鼠标移到上方时,的高度在增加,并且用表示.frameanimate.frame.top.bottom.fadeIn()

当鼠标移出时.frame,的大小.frame会减小,并且.top.bottom一起消失.fadeOut()

我的CSS是:

.frame{
        border-style: solid;
        border-width: 1px;
        width:200px;
        height:200px;
        position: absolute;
        top:50px;
        left:50px;
    }

    .middle{
        width:100%;
        position: absolute;
    }

    .top{
        display:none;
        background-color:red;
        width:100%;
    }

    .bottom{
        position:absolute;
        display:none;
        bottom:0px;
        background-color:red;
        width:100%;
    }

我的HTML:

<div class="frame">
    <div class="top">top</div>
    <div class="middle">middle</div>
    <div class="bottom">bottom<br>bottom<br>bottom<br>bottom</div>
</div>

和我的jQuery:

$(document).on('mouseenter mouseleave', '.frame', function( e ) {
        var el = $(this),
            top = el.children('.top'),
            bottom = el.children('.bottom'),
            middle = el.children('.middle'),
            d = bottom.height()+20,
            mEnt = e.type == "mouseenter";

        if(mEnt == true){
            middle.stop().animate({'top':'20px'});
            el.stop().animate({
                'height':'+='+d,
                'top':'-=20'
            }); 
            top.stop().fadeIn(300);
            bottom.stop().fadeIn(300);
        }else{
            middle.stop().animate({'top':'0px'});
            el.stop().animate({
                'height':'-='+d,
                'top':'+=20'
            });
            top.stop().fadeOut(300);
            bottom.stop().fadeOut(300);
        }
    });

这是一个jsFiddle:http : //jsfiddle.net/malamine_kebe/Y6cbQ/

它运行良好,但是当鼠标快速进入和离开时,整个事情变得一团糟。我先放了一个.stop().animate()但似乎无济于事。

罗伯托·普欧

代替.stop()使用.stop(true, true)这样就可以清除动画队列,并立即完成当前动画(http://api.jquery.com/stop/)。

您可以在小提琴中看到:http : //jsfiddle.net/3gYtK/

$(document).on('mouseenter mouseleave', '.frame', function( e ) {
    var el = $(this),
        top = el.children('.top'),
        bottom = el.children('.bottom'),
        middle = el.children('.middle'),
        d = bottom.height()+20,
        mEnt = e.type == "mouseenter";

    if(mEnt == true){
        middle.stop().animate({'top':'20px'});
        el.stop(true, true).animate({
            'height':'+='+d,
            'top':'-=20'
        }); 
        top.stop(true, true).fadeIn(300);
        bottom.stop(true, true).fadeIn(300);
    }else{
        middle.stop().animate({'top':'0px'});
        el.stop(true, true).animate({
            'height':'-='+d,
            'top':'+=20'
        });
        top.stop(true, true).fadeOut(300);
        bottom.stop(true, true).fadeOut(300);
    }
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

jQuery stop()和animate()函数问题

来自分类Dev

jQuery animate()函数遇到问题

来自分类Dev

jQuery .animate()和.done()

来自分类Dev

jquery:$()。animate()不是函数

来自分类Dev

jQuery .animate意外动作

来自分类Dev

滚动时的jquery .animate()

来自分类Dev

jQuery animate()divs打开

来自分类Dev

jQuery .animate离开页面

来自分类Dev

jQuery反转.animate并触发?

来自分类Dev

jQuery animate()更改文本

来自分类Dev

jQuery Animate动态转换

来自分类Dev

jQuery的mouseenter和mouseleave问题

来自分类Dev

使用'.animate()'函数的功能问题

来自分类Dev

悬停时的jQuery Animate高度

来自分类Dev

jQuery-animate()无法停止?

来自分类Dev

jQuery .animate()无法正常工作

来自分类Dev

Firefox中的jQuery animate()Buggy

来自分类Dev

jQuery .animate()不起作用

来自分类Dev

通过animate()JQUERY获得进度

来自分类Dev

jQuery animate()使用keydown平滑

来自分类Dev

jQuery .animate()导致跳动输入

来自分类Dev

jQuery .animate无法正常工作

来自分类Dev

jQuery .slideUp在.animate之前执行

来自分类Dev

.animate jQuery无法正常工作

来自分类Dev

jQuery .animate()无法正常工作

来自分类Dev

CSS定位和jQuery .animate

来自分类Dev

Firefox中的jQuery animate()Buggy

来自分类Dev

jQuery此+ class.animate()

来自分类Dev

jQuery animate()使用keydown平滑