【问题标题】:Does animate.style support on hover animationanimate.style 是否支持悬停,因为我正在尝试悬停动画
【发布时间】:2021-08-29 12:08:47
【问题描述】:

我想使用animate.style 来显示悬停而不是页面加载的动画效果,animate.style 的新版本 animate.css 似乎没有文档中提到的悬停部分。

不确定这是否受支持或有其他方法。

指向这个方向的指针会很有帮助,因为我想让所有动画都悬停在移动中

.d-flex  div {background:red;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.1/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/5.0.1/cerulean/bootstrap.min.css" rel="stylesheet"/>
  <div class="container-fluid my-5 bg-light">
    <div class="row">
        <div class="col-12 p-0">
            <div class="container py-5 text-center">
                <div class="row">
                    <div class="col-12"><h1>AMENITIES</h1></div>
                </div>
                <div class="row p-2">
                    <div class="col-lg-3 col-md-6 col-sm-12 p-3 ">
                        <div class="shadow-sm bg-white p-3"><img class="img-fluid animate__animated animate__lightSpeedInRight" style="max-width:80px" src="https://img.icons8.com/wired/2x/ccleaner.png" /><p>90 Berth Marina and Yacht Club</p></div></div>
                    <div class="col-lg-3 col-md-6 col-sm-12 p-3">
                        <div class="shadow-sm bg-white p-3"><img class="img-fluid animate__animated animate__flip" style="max-width:80px" src="https://img.icons8.com/wired/2x/ccleaner.png" /><p>Excelllent Hospitality Experiences</p></div></div>
                    <div class="col-lg-3 col-md-6 col-sm-12 p-3">
                        <div class="shadow-sm bg-white p-3"><img class="img-fluid animate__animated animate__rotateIn" style="max-width:80px" src="https://img.icons8.com/wired/2x/ccleaner.png" /><p>Seaside and Marina Promenades</p></div></div>
                    <div class="col-lg-3 col-md-6 col-sm-12 p-3">
                        <div class="shadow-sm bg-white p-3"><img class="img-fluid animate__animated animate__rotateIn" style="max-width:80px" src="https://img.icons8.com/wired/2x/ccleaner.png" /><p>Private Landscaped Terraces</p></div></div>
                    <div class="col-lg-3 col-md-6 col-sm-12 p-3">
                        <div class="shadow-sm bg-white p-3"><img class="img-fluid animate__animated animate__rotateIn" style="max-width:80px" src="https://img.icons8.com/wired/2x/ccleaner.png" /><p>Private Facilities and Amenities</p></div></div>
                    <div class="col-lg-3 col-md-6 col-sm-12 p-3">
                        <div class="shadow-sm bg-white p-3"><img class="img-fluid animate__animated animate__rotateIn" style="max-width:80px" src="https://img.icons8.com/wired/2x/ccleaner.png" /><p>Swimming Pools</p></div></div>
                    <div class="col-lg-3 col-md-6 col-sm-12 p-3">
                        <div class="shadow-sm bg-white p-3"><img class="img-fluid animate__animated animate__rotateIn" style="max-width:80px" src="https://img.icons8.com/wired/2x/ccleaner.png" /><p>Beach Access</p></div></div>
                    <div class="col-lg-3 col-md-6 col-sm-12 p-3 h-100">
                        <div class="shadow-sm bg-white p-3"><img class="img-fluid animate__animated animate__rotateIn" style="max-width:80px" src="https://img.icons8.com/wired/2x/ccleaner.png" /><p>Cafes</p></div></div>

                </div>
          </div>
        </div>
    </div>
  </div>

<br><br>
<br>
<br>




<div class="d-flex flex-row bd-highlight mb-3">
  <div class="p-2 bd-highlight m-3">Flex item 1</div>
  <div class="p-2 bd-highlight m-3">Flex item 2</div>
  <div class="p-2 bd-highlight m-3">Flex item 3</div>
  <div class="p-2 bd-highlight m-3">Flex item 4</div>
  <div class="p-2 bd-highlight m-3">Flex item 5</div>
  <div class="p-2 bd-highlight m-3">Flex item 6</div>
  <div class="p-2 bd-highlight m-3">Flex item 7</div>
</div>

在旧版本中我使用 jQuery 实现了这一点,但这在新版本中不起作用

$(".wrapper").hover(function () {
        $(this).addClass("iconimage animated flipInY").delay(300);
        setTimeout(function () {
            $(this).addClass("iconimage animated flipInY");
        }, 200);
    }, function () {
        
        setTimeout(function () {
          
        }, 1000);
    });

    $(".SponsorLogoImg").mouseout(function () {
        
        setTimeout(function () {
         
        }, 100);
    });

【问题讨论】:

    标签: html css animation animate.css


    【解决方案1】:

    您可以为此使用 JavaScript 或 jQuery。

    例如:-

    $(elem).mouseover(function(){
      $(this).addClass("animate__animated animate__flip");
      //You can add some other classes as well
    }); 
    //If you want the animation to happen every time you hover on element
    $(elem).mouseout(function(){
      $(this).removeClass("animate__animated animate__flip");
    });
    

    1 个或多个动画

    $(elem).mouseover(function(){
        $(this).addClass("animate__animated animate__flip");
        //You can add some other classes as well
        this.addEventListener('animationend',() => {
           $(this).removeClass("animate__animated animate__flip");
           //the second animation now
           $(this).addClass("animate__animated animate__bounce");
        });
    });
    

    附加内容

    有一个库animate.css-dynamic 可以简单地与一些实用程序类等一起使用。

    对于您使用此库的情况,您可以执行以下操作。

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" rel="stylesheet"/>
    <script src="https://cdn.jsdelivr.net/gh/KodingKhurram/animate.css-dynamic@main/animate.min.js"></script>
    
    <h2 align="center"> Mouse over or click the image to animate</h2>
    <img class="img-fluid ani_flip aniUtil_onMouse aniUtil_onClick aniUtil_active" style="max-width:80px" src="https://img.icons8.com/wired/2x/ccleaner.png" /><p>Excelllent Hospitality Experiences</p></div></div>

    访问here 获取详细文档。

    【讨论】:

      【解决方案2】:

      例如,如果你这样做,目标动画将被执行。

      使用ID代替目标类可以缩小影响范围。

      .animate__animated:hover {
          animation-name: flip;
          animation-duration: 1s;
      }
      

      【讨论】:

      • 这行得通,谢谢,我希望悬停时有一个单独的调用,因为我对不同的图标有不同的动画......也许我会为所有不同的图标调用不同的动画......这比 JS 更好我也修复了但只在悬停时运行一次的版本...
      • 我认为还有更好的方法。如果您添加一个空动画,您可能能够再次执行与该类关联的动画。
      • 我也试试
      • 我尝试了.animate__animated:hover { animation-name: lightSpeedInRight; animation-duration: 1s; },但它不起作用,当我将其更改为翻转时它起作用但不是lightSpeedInRight
      • stackoverflow.com/questions/23114753/restart-animation-on-hover悬停时需要动画,感觉悬停侧设置Animation很有必要。
      猜你喜欢
      • 2019-09-01
      • 2012-12-01
      • 2021-04-02
      • 2021-03-16
      • 1970-01-01
      • 1970-01-01
      • 2020-10-14
      • 2015-09-25
      • 2014-09-22
      相关资源
      最近更新 更多