javascript - JQuery - 如果你不是,请执行此操作。将此 div 悬停

标签 javascript jquery css hover jquery-animate

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 个处理程序 - 对于 mouseentermouseleave ,或者像您一样,一个处理程序可以两者。但由于您希望悬停“进出”行为...请使用 2 处理程序版本。

关于javascript - JQuery - 如果你不是,请执行此操作。将此 div 悬停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4386596/

相关文章:

javascript - 在 React 的秒表中每秒旋转秒数

javascript - document.addEventListener ("Mousemove") 会降低 WEBGL 的性能吗?

jquery - 克隆日期选择器输入不起作用

javascript - HTML复选框在JavaScript/Jquery中打开文本放大功能但无法关闭

javascript - 时间轴 JScript 在 IExplorer 中不起作用

HTML + CSS - 悬停时缩放图像

javascript - 如何刷新页面中的特定div?

javascript - 根据第一个下拉值填充第二个下拉列表

javascript - 如何在jquery中动态设置属性?

javascript - 使用 jQuery 从 ajax/jsonp 请求输出 html