简体   繁体   English

手机屏幕AOS animation怎么关闭?

[英]How to turn off AOS animation in mobile screens?

Can anyone please tell me how to turn of animations of my page when it's being viewed by a mobile device?谁能告诉我如何在移动设备查看我的页面时关闭动画?

I'm using aos library for css to add some animation to my page.我正在使用 css 的 aos 库向我的页面添加一些 animation。 But I want to turn that animation off on mobile devices.但我想在移动设备上关闭 animation。 Any help on that regard will be greatly appreciated.在这方面的任何帮助将不胜感激。 Thanks!谢谢!

Link of the library: https://michalsnik.github.io/aos/图书馆链接: https://michalsnik.github.io/aos/

Maybe you want to do it with CSS but it can be easy with JS.也许你想用 CSS 来做,但用 JS 很容易。 You can use optional settings object on your JS file where you initialize AOS like this:您可以在初始化 AOS 的 JS 文件中使用可选设置对象,如下所示:

AOS.init({disable: 'mobile'});

Here you can use following values: 'phone', 'tablet', 'mobile', boolean, expression or function在这里您可以使用以下值:'phone'、'tablet'、'mobile'、布尔值、表达式或函数

For more options check https://github.com/michalsnik/aos有关更多选项,请查看https://github.com/michalsnik/aos

You can use this js to specify when exactly you want to disable it.您可以使用此 js 来指定您想要禁用它的确切时间。

AOS.init({
  disable: function() {
    var maxWidth = 800;
    return window.innerWidth < maxWidth;
  }
});

try this one it worked for me:试试这个对我有用的:

/* Small Devices, Tablets */
@media only screen and (max-width : 768px) {
    .animated {
        /*CSS transitions*/
        -o-transition-property: none !important;
        -moz-transition-property: none !important;
        -ms-transition-property: none !important;
        -webkit-transition-property: none !important;
        transition-property: none !important;
        /*CSS transforms*/
        -o-transform: none !important;
        -moz-transform: none !important;
        -ms-transform: none !important;
        -webkit-transform: none !important;
        transform: none !important;
        /*CSS animations*/
        -webkit-animation: none !important;
        -moz-animation: none !important;
        -o-animation: none !important;
        -ms-animation: none !important;
        animation: none !important;
    }
}

None of the solutions worked for me,没有一个解决方案对我有用,

The only way I was able to disable animations on mobile was by wrapping the content of aos.css within a media query such as:我能够在移动设备上禁用动画的唯一方法是将 aos.css 的内容包装在媒体查询中,例如:

@media only screen and (min-width:750px) {
 
 /* paste here ​all the content of the aos.css file */    

}

This works perfectly because it doesn't overide CSS that elements could have, disables the animation without interring.这非常有效,因为它不会覆盖元素可能具有的 CSS,禁用动画而不会产生干扰。 Combined with Mahidul Isalm Mukto's response It was the full solution.结合 Mahidul Isalm Mukto 的回应这是完整的解决方案。

Similar to An's answer, but the class is different.类似于An的答案,但班级不同。 This will work as of 2022 - change class to 'aos-animate':这将从 2022 年开始工作 - 将类更改为“aos-animate”:

@media only screen and (max-width: 768px) {
  .aos-animate {

    -o-transition-property: none !important;
    -moz-transition-property: none !important;
    -ms-transition-property: none !important;
    -webkit-transition-property: none !important;
    transition-property: none !important;

    -o-transform: none !important;
    -moz-transform: none !important;
    -ms-transform: none !important;
    -webkit-transform: none !important;
    transform: none !important;

    -webkit-animation: none !important;
    -moz-animation: none !important;
    -o-animation: none !important;
    -ms-animation: none !important;
    animation: none !important;
  }
}

2022 update . 2022 年更新

This worked for me in aos 2.3.4".这在 aos 2.3.4" 中对我有用。

@media screen and (max-width: 600px) {
  .aos-animate {
    transition-property: none !important;
    transform: none !important;
    animation: none !important;
  }
}

Add this on div you input AOS animation在你输入 AOS animation 的 div 上添加这个

@media only screen and (max-width:700px) {
    .class-name {
      opacity: 1 !important;
      transform: translate(0) scale(1) !important;
    }
}

it's worked for me rn它对我有用 rn

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM