javascript - JQuery - Do this if you're NOT .hover this div - Stack Overflow

cardh = 0$('.cardgreen > img').hover(function () {if (cardh == 0) {$('.card > img&

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
    }
});

How to say JQuery: DO THE 2nd thing when you're not hovering the div > img anymore..?

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
    }
});

How to say JQuery: DO THE 2nd thing when you're not hovering the div > img anymore..?

Share Improve this question edited Oct 11, 2011 at 20:58 Jacob Mattison 51.1k11 gold badges108 silver badges128 bronze badges asked Dec 8, 2010 at 10:49 TomkayTomkay 5,16021 gold badges65 silver badges94 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

The second function you pass to .hover() is the mouseleave handler, like this:

$('.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() takes 2 handlers - for mouseenter and mouseleave, or like you had, a single handler that does both. But since you want hover "in and out" behavior...use the 2 handler version.

the jQuery .hover() method can take 2 arguments (see here: http://api.jquery./hover/).

.hover( handlerIn(eventObject), handlerOut(eventObject) )

handlerIn(eventObject) - A function to execute when the mouse pointer enters the element. handlerOut(eventObject) - A function to execute when the mouse pointer leaves the element.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742362433a4429649.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信