jQuery Slide on悬停单独的移动

时间:2013-01-25 15:15:57

标签: javascript jquery mouseover

如果鼠标结束,我在一些帮助下制作了一个Text来移动文本。我的问题是我不能分开这些动作。如果我超过任何Box,那么所有Box都会产生效果。

$(document).ready(function(){
    $('.up-down').mouseover(function(){
        $('.default').stop().animate({
            height: 200    
        }, 200);                        
    }).mouseout(function(){
        $('.default').stop().animate({
            height: 240 
        }, 200)    
    })
});

要查看此处:http://jsfiddle.net/snHhN/

2 个答案:

答案 0 :(得分:2)

您必须选择当前悬停元素的子元素:

$(document).ready(function(){
    $('.up-down').mouseover(function(){
        $(this).children('.default').stop().animate({
            height: 200    
        }, 200);                        
    }).mouseout(function(){
        $(this).children('.default').stop().animate({
            height: 240 
        }, 200)    
    })
});

DEMO

答案 1 :(得分:0)

因为你正在使用$('.default'),所以任何具有类默认值的元素都将被采取行动。

如果.default在.up-down内,你可以使用

$(this).find('.default')

......它只会对正确的元素起作用。