2016-06-22 3 views
0

나는 마우스 입력시 애니메이션 클래스를 추가하고 마우스가 요소를 떠날 때 다른 클래스를 추가하는 jQuery를 기본적으로 가지고 있으며 In 및 Out 애니메이션을 원한다. 페이딩을 얻고 있습니다. 애니메이션에서 마우스로 떠날 때, 요소는 애니메이션없이 사라집니다. 따라서 보여주는 것만 움직일 수는 있지만 떠나는 것은 아닙니다.jQuery로 들어가고 떠나는 CSS 애니메이션

jQuery를 :

$('.menu > ul > li').on({ 
      mouseenter: function() { 
       if (getWindowWidth() >= responsiveBreakpoint) { 
        $(this).children('ul').removeClass('fadeOutUp').addClass('fadeInDown'); 
       } 
      }, 
      mouseleave: function() { 
       if (getWindowWidth() >= responsiveBreakpoint) { 
        $(this).children('ul').removeClass('fadeInDown').addClass('fadeOutUp'); 
       } 
      } 
     }); 

CSS

@keyframes fadeInDown { 
    from { 
    display: none; 
    opacity: 0; 
    transform: translate3d(0, -20px, 0); 
    } 

    to { 
    display: block; 
    opacity: 1; 
    transform: none; 
    } 
} 

.fadeInDown { 
    animation: .2s ease; 
    animation-name: fadeInDown; 
} 

@keyframes fadeOutUp { 
    from { 
    display: block; 
    opacity: 1; 
    transform: none; 
    } 

    to { 
    display: none; 
    opacity: 0; 
    transform: translate3d(0, -20px, 0); 
    } 
} 

.fadeOutUp { 
    animation: .2s ease; 
    animation-name: fadeOutUp; 
} 

그리고 애니메이션을하려고 메신저 요소는 다음과 같은 스타일입니다 :

> ul { 
     display: none; 
     position: absolute; 
     z-index: 99; 
     left: 0; 
     width: 100%; 
     background: $hover-and-dropdown-bg; 
} 
+3

은'display'는 애니메이션 할 수 없습니다. 또는 표시되거나 숨겨집니다. 중간 수준이 아닙니다. 불투명도의 종류 또는 이와 유사한 것을 사용하십시오. 그러나 자바 스크립트 코드가 필요 없다고 생각합니다. 애니메이션이 어린이에서 발생하기 때문에 동일한 순수 CSS (': hover' pseudoclass)를 얻을 수 있습니다. –

+0

나는 마우스에서 디스플레이 애니메이션을 관리 내 코드에서 어떻게 봐야, 그냥 다른 방법으로, 마우스 왼쪽에서 떠날 – riogrande

+0

** NO **. 당신은'opacity'를 애니메이트하고 있지만'display'는 애니메이트하지 않습니다. 왜냐하면'display'는 스펙과 로직에 의해 불가능하기 때문입니다. –

답변

0

좋아, 내가 그것을 어떻게 관리, 그래서 내가 속임수 CSS는 디스플레이 속성을 가진 애니메이션을 가지고 있습니다.

JQuery와

$('.menu > ul > li').on({ 
      mouseenter: function() { 
       if (getWindowWidth() >= responsiveBreakpoint) { 
        $(this).children('ul').css('display', 'block').removeClass('fadeOutUp').addClass('fadeInDown'); 
       } 
      }, 
      mouseleave: function() { 
       if (getWindowWidth() >= responsiveBreakpoint) { 
        $(this).children('ul').removeClass('fadeInDown').addClass('fadeOutUp').delay(200).queue(function (next) { 
         $(this).css('display', 'none'); 
         next(); 
        }); 
       } 
      } 
     }); 
관련 문제