jquery在mouseout上返回原始状态

jquery在mouseout上返回原始状态,jquery,mouseout,Jquery,Mouseout,我们正在更改悬停时html中的一些内容: $('.zentriert') .hover(function(){ if(!$(this).is(".open")) { $(this).animate({opacity: 1}, 150); $(this).find('img').css({'position': 'relative'}).animate({top: -10}, 150); $(this).find('.beschreibung').css({'dis

我们正在更改悬停时html中的一些内容:

$('.zentriert')
.hover(function(){
    if(!$(this).is(".open")) {
    $(this).animate({opacity: 1}, 150);
    $(this).find('img').css({'position': 'relative'}).animate({top: -10}, 150);
    $(this).find('.beschreibung').css({'display': 'block'}).animate({opacity: 1, top: -10}, 150);
    $(this).addClass('open')
    }})
在mouseout上,让一切恢复到原始状态的最佳方法是什么?这不起作用:

$('.zentriert')
.mouseout(function(){
    if($(this).is(".open")) {
    $(this).animate({opacity: 0.17}, 150);
    $(this).find('img').animate({top: 10}, 150);
    $(this).find('.beschreibung').animate({opacity: 0, top: 10}, 150).css({'display': 'none'});
    $(this).removeClass('open')
    }})

提前感谢您的帮助

jQuery中的悬停事件使用2个回调函数。第一个在用户悬停项目时触发,第二个在项目离开时触发

试一试


hover有两个功能。一个是mouseover,一个是mouseout。在反复使用时,应该将
$(this)
定义为一个变量。
$(".zentriert").hover(
   function() {
     if(!$(this).is(".open")) {
    $(this).animate({opacity: 1}, 150);
    $(this).find('img').css({'position': 'relative'}).animate({top: -10}, 150);
    $(this).find('.beschreibung').css({'display': 'block'}).animate({opacity: 1, top: -10}, 150);
    $(this).addClass('open')
    }
   },
   function() {
     if($(this).is(".open")) {
    $(this).animate({opacity: 0.17}, 150);
    $(this).find('img').animate({top: 10}, 150);
    $(this).find('.beschreibung').animate({opacity: 0, top: 10}, 150).css({'display': 'none'});
    $(this).removeClass('open')
    }
   }
);