简体   繁体   English

使用带有 Svelte 套件的 AOS 动画时遇到问题

[英]Having issues using AOS animation with svelte kit

I'm using for the first time svelte for a portfolio and coming from React I must say it's really fun and easy to use !我第一次将 svelte 用于投资组合并且来自 React 我必须说它非常有趣且易于使用!

But recently i had issues using AOS with svelte kit.但最近我在使用带有 svelte 套件的 AOS 时遇到了问题。 Mostly when I'm going from a page to another using href the animations won't load.大多数情况下,当我使用 href 从一个页面转到另一个页面时,动画不会加载。 But when i'm refreshing the page (with cmd+R) it works again.但是当我刷新页面(使用 cmd+R)时,它又可以工作了。

The link to the repo回购链接

I'm using this method in my __layout.svelte.我在我的 __layout.svelte 中使用了这个方法。 Putting it in onMount or not doesn't change anything.是否将其放入 onMount 不会改变任何东西。


    onMount(() => {
        AOS.init();
    });

Then in another page i'm using AOS like below然后在另一个页面中,我正在使用 AOS,如下所示

        <h1
            data-aos="slide-right"
            data-aos-duration="1000"
        >
            Allianz France
        </h1>

And to go from page to page i'm using并从一个页面到另一个页面我正在使用

            <a
                href="allianz"
                sveltekit:reload
                out:fly|local={{ x: -200, duration: 1000, delay: 300 }}
                in:fly={{ x: 200, duration: 1000, delay: 1300 }}
                id="allianz"
            >

Using sveltekit:reload does not change anything.使用 sveltekit:reload 不会改变任何东西。

package.json包.json

"aos": "^3.0.0-beta.6"

The AOS ( A nimate o n S croll) library will look inside the DOM for elements with the data-aos attributes, it even watches for DOM changes. AOS( A nimate on S croll)库将在 DOM 中查找具有 data-aos 属性的元素,它甚至会监视 DOM 的变化。

That feature has limitations.该功能有局限性。 When Svelte manages the DOM or the layout changes based on other factors the AOS library needs a little help.当 Svelte 管理 DOM 或基于其他因素更改布局时,AOS 库需要一点帮助。

AOS.refresh();

When you should call that method depends on your app.何时调用该方法取决于您的应用程序。

Tip : For debugging add window.AOS = AOS;提示:调试添加window.AOS = AOS; inside an onMount , that allows calling the OAS.refresh() from the console.onMount中,允许从控制台调用OAS.refresh()

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

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