简体   繁体   English

如何将 ScrollOut js 添加到 Nuxtjs

[英]How to add ScrollOut js to Nuxtjs

I need your help to add scrollOut js in Nuxt js project.我需要你的帮助在 Nuxt js 项目中添加 scrollOut js。 I am getting window not defined error.我收到窗口未定义错误。

I have followed Nuxt's guidlines of adding a plugin like我已经按照 Nuxt 的指南添加了一个插件,比如

if (process.client) {
  require('external_library')
}

However this isn't working for me even after adding the plugin in the nuxt.config.js file但是,即使在 nuxt.config.js 文件中添加插件后,这对我也不起作用

import ScrollOut from "scroll-out";

export default {
  methods: {
    textAnim() {
      TweenMax.set("#logo, .hidetext, #about-text", { visibility: 'visible' })
      const tl = new TimelineMax();
        tl.from("#logo path", 1, { stroke: "white", drawSVG: "0" });
        tl.to("#s_1_", .5, { fill: "white", stroke: "none" }, "-=.3")
        tl.to("#k_1_", .5, { fill: "gray", stroke: "none"}, "-=.3")
        tl.staggerFrom(".hidetext", 1, { y: "130%", ease: Power4.easeOut }, 0.5);
        tl.from("#about-text", 0.5, { alpha: 0, y: 50, ease: Power1.easeOut }, "-=.5");
    }
  },
  mounted() {
    ScrollOut({
      targets: "h3, [data-splitting], ul li",
      threshold: .5
    });
    this.textAnim();
  },
  components: {
    Logo
  }
};

Also in my package.json file I see "nuxt": "^2.0.0", version.同样在我的 package.json 文件中,我看到"nuxt": "^2.0.0",版本。 I created the project using create-nuxt-app .我使用create-nuxt-app创建了该项目。

Any help is really appreciated.任何帮助都非常感谢。

Thanking you感谢您

create a file as plugins/scroll-out.js and write:创建一个文件作为 plugins/scroll-out.js 并写入:

import ScrollOut from "scroll-out";

in nuxt.config.js在 nuxt.config.js 中

modules: [
  ...
  { src: '~/plugins/scroll-out.js', mode: 'client' }
  ...
]

this can make your plugin load client-side only这可以使您的插件仅在客户端加载

here is document https://nuxtjs.org/guide/plugins#client-side-only这是文档https://nuxtjs.org/guide/plugins#client-side-only

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

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