2

我尝试创建一个 CSS 动画,当您将鼠标悬停在框上时,它会使用 CSS 动画显示 div。我已使用以下站点作为参考。单击此处,但是我似乎无法实现 efx。在我的网站上,我将 JqUERY 用于显示和隐藏功能,我的 addClass 和 RemoveClass 可以工作,但总体而言,该功能无法正常工作。有人可以指导我正确的方向。

/ ** HTML * * /

div class="box">
        <div class="trigger">hhh</div>
            <div class="overlay">
                <h1>box 1</h1>
            </div>
        </div>

<div class="box">
<div class="trigger">hhh</div>
      <div class="overlay">
            <h1>box 1</h1>
        </div>
    </div>

<div class="box">
<div class="trigger">hhh</div>
    <div class="overlay">
            <h1>box 1</h1>
        </div>
    </div>

/ * jQuery **/

                     $(".overlay").addClass("visible");
        $(".overlay").removeClass("visible");
            $(".trigger").hover(function(){
                var $this = $(this);
                $this.next(".overlay").addClass("visible");
            }); 

            $(".trigger").mouseleave(function(){
                var $this = $(this);
                $this.next(".overlay").removeClass("visible");
            }); 

/ ** CSS 动画 ** /

.fadeInDown {
-webkit-animation-name: fadeInDown;
-moz-animation-name: fadeInDown;
-o-animation-name: fadeInDown;
animation-name: fadeInDown;
-webkit-animation-duration: 1s;
-webkit-animation-delay: 2s;
-webkit-animation-timing-function: ease;
-webkit-animation-fill-mode: both;

-moz-animation-duration: 1s;
-moz-animation-delay: 2s;
-moz-animation-timing-function: ease;
-moz-animation-fill-mode: both;

-o-animation-duration: 1s;
-o-animation-delay: 2s;
-o-animation-timing-function: ease;
-o-animation-fill-mode: both;

animation-duration: 1s;
animation-delay: 2s;
animation-timing-function: ease;
animation-fill-mode: both;
    }


     @-webkit-keyframes fadeInDown {
0% {
    opacity: 0;
    -webkit-transform: translateY(-20px);
}

100% {
    opacity: 1;
    -webkit-transform: translateY(0);
}
      }


     .fadeInUp {
-webkit-animation-name: fadeInUp;
-moz-animation-name: fadeInUp;
-o-animation-name: fadeInUp;
animation-name: fadeInUp;
-webkit-animation-duration: 1s;
-webkit-animation-delay: 2s;
-webkit-animation-timing-function: ease;
-webkit-animation-fill-mode: both;

-moz-animation-duration: 1s;
-moz-animation-delay: 2s;
-moz-animation-timing-function: ease;
-moz-animation-fill-mode: both;

-o-animation-duration: 1s;
-o-animation-delay: 2s;
-o-animation-timing-function: ease;
-o-animation-fill-mode: both;

animation-duration: 1s;
animation-delay: 2s;
animation-timing-function: ease;
animation-fill-mode: both;
        }

      @-Webkit-keyframes fadeInUp {
0% {
    opacity: 0;
    -moz-transform: translateY(20px);
}
4

2 回答 2

1

添加以下 css 和 HTML 标签。

HTML 代码:-

<h1 class="animated fadeInUp" >Example</h1>

CSS代码:-

.animated {
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
}
@keyframes fadeInUp {
  from {
    opacity: 0;
    -webkit-transform: translate3d(0, 100%, 0);
    transform: translate3d(0, 100%, 0);
  }

  to {
    opacity: 1;
    -webkit-transform: none;
    transform: none;
  }
}

.fadeInUp {
  -webkit-animation-name: fadeInUp;
  animation-name: fadeInUp;
}
于 2015-12-02T18:50:38.603 回答
0

Try using the css classes that you have provided, and pass a second parameter to the "addClass" call indicating the number of milliseconds that it should animate. For example:

$(".trigger").hover(function(){
    var $this = $(this);
    $this.next(".overlay").addClass("fadeInDown", 1000);
}); 
于 2013-08-20T14:40:57.227 回答