cardh = 0
$('.cardgreen > img').hover(function () {
if (cardh == 0) {
$('.card > img').animate({ height: 150, width: 193, opacity: '1', left: 0, top: 9 }, 500);
$('.anfahrtlink').animate({ opacity: '0' }, 500).animate({ width: 0 }, 0);
$('.cardgreen > img').animate({ opacity: '0' }, 500).animate({ opacity: '1' }, 500);
cardh = 1
}
});
$('.cardgreen > img').notanymore().hover(function () {
if (cardh == 1) {
$('.cardgreen > img').animate({ opacity: '0' }, 300);
$('.anfahrtlink').animate({ width: 84 }, 0).animate({ opacity: '1' }, 500);
$('.card > img').animate({ opacity: '1' }, 300).animate({ opacity: '0', width: 0, height: 0, left: 194, top: 75}, 270);
cardh = 0
}
});
如何说 JQuery:当您不再悬停 div > img 时做第二件事..?
最佳答案
传递给 .hover()
的第二个函数是 mouseleave
处理程序,如下所示:
$('.cardgreen > img').hover(function() {
$('.card > img').animate({height: 150, width: 193, opacity: '1', left: 0, top: 9},500)
$('.anfahrtlink').animate({opacity: '0',},500).animate({width:0},0);
$('.cardgreen > img').animate({opacity: '0'},500)
.animate({opacity: '1'},500);
}, function() {
$('.cardgreen > img').animate({opacity: '0'},300);
$('.anfahrtlink').animate({width:84},0).animate({opacity: '1',},500)
$('.card > img').animate({opacity: '1'},300)
.animate({opacity: '0', width: 0, height: 0, left:194, top:75},270);
});
.hover()
需要 2 个处理程序 - 对于 mouseenter
和 mouseleave
,或者像您一样,一个处理程序可以两者。但由于您希望悬停“进出”行为...请使用 2 处理程序版本。
关于javascript - JQuery - 如果你不是,请执行此操作。将此 div 悬停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4386596/