3

我正在使用wow.jswithanimate.js在鼠标滚动上显示动画。

我想改变小设备上的动画方向,比如在大屏幕上它应该从右边开始动画,在小设备上它应该从底部开始动画。

这是一个片段来显示我需要什么。

new WOW().init();
<script src="https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css" rel="stylesheet"/>
  <section class="wow fadeInRight" >Section 1</section>
  <section class="wow fadeInUp"  data-wow-delay="1s">Section 1 on mobile</section>

4

3 回答 3

0
  1. fadeInRight从您的 html 中删除类。
  2. 使用 JS 检测屏幕宽度。
  3. 如果小于或等于 1024,则添加fadeInUp到元素,否则添加fadeInRight到元素。

  const wow = document.querySelectorAll('.wow')
  const dir = window.innerWidth <= 1024 ? 'fadeInUp' : 'fadeInRight'
  Array.prototype.forEach.call(wow, el => el.classList.add(dir))

new WOW().init();
<script src="https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css" rel="stylesheet"/>
  <section class="wow" >Section 1</section>
  <section class="wow"  data-wow-delay="1s">Section 1 on mobile</section>

于 2018-03-06T14:58:03.150 回答
0

我认为您不必为此使用两个内容,只需使用一个元素并更改移动设备的动画类即可。你可以减少内容。

我只是添加一个媒体查询来更改动画类 anime.min.css

您可以更改媒体查询值(767px)

new WOW().init();
@media only screen and (max-width: 767px) {
  .anim-mob-up.fadeInRight {
    -webkit-animation-name: fadeInLeft !important;
    animation-name: fadeInLeft !important;	
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css" rel="stylesheet"/>


<section class="wow fadeInRight anim-mob-up">Section 1 Both Desk & Mobile</section>

于 2018-03-06T10:41:29.323 回答
0

你可以简单地这样做:

new WOW().init();
.desktop {
  display: block;
}

.mobile {
  display: none;
}

@media all and (max-width:767px) {
  .desktop {
    display: none;
  }
  .mobile {
    display: block;
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css" rel="stylesheet" />
<section class="wow fadeInRight desktop">Section 1</section>
<section class="wow fadeInUp mobile">Section 1 on mobile</section>

于 2018-03-06T10:57:27.910 回答