2010-12-08 3 views
2
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 : do you do you do div> img 더 이상 ..?JQuery -이 작업을 수행하지 않는 경우이 작업을 수행하십시오.

답변

4

당신이 .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 처리기 버전을 사용하십시오.

+0

하지만 이렇게하면 호버린이 울리며 항상 호버 .. – Tomkay

+0

@ Mr.Freeman - 그럴리가 없어, 예제 페이지가 있습니까? –

+0

죄송합니다 닉 - 코드와 함께 작동하지 않습니다 .. 감사합니다. – Tomkay

2

jQuery .hover() 메서드는 2 개의 인수를 취할 수 있습니다 (여기를 참조하십시오 : http://api.jquery.com/hover/ 참조).

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

handlerIn (eventObject) - 마우스 포인터가 요소에 들어갈 때 실행되는 함수입니다. handlerOut (eventObject) - 마우스 포인터가 요소를 벗어날 때 실행되는 함수입니다.

관련 문제