Open ddiegommachado opened 5 years ago
Me neither it does not seems to work ...
plugin/aos.js
import Vue from 'vue'
import AOS from 'aos'
import 'aos/dist/aos.css'
Vue.use(AOS, {
disable: 'phone'
})
nuxt 2.5.1
Hi @ddiegommachado, @jb-reynaud. Sorry, I wasn't active. You may have already solved the issue by now haha 😅
Anyway, I changed my example for AOS. You can see the tutorial here and the working demo here.
These are the important parts:
// nuxt.config.js
export default {
plugins: [{ src: "~/plugins/aos", ssr: false }],
}
// plugins/aos.js
import AOS from "aos";
import "aos/dist/aos.css";
export default ({ app }) => {
app.AOS = new AOS.init({ disable: "phone" }); // or any other options you need
};
You don't need to import Vue in the plugin.
To see everything, just browse the repo. Hope this help!
Hey @yasminzy , it's possible access AOS inside a component or page? I need run AOS.refresh() inside a page mount lifecycle and I don't know how. Any idea?
Hey @yasminzy your plugin works beautifully when i am in the development environment.
However, after running npm run generate and pushing my static build to production, i have an issue whereby the animation runs a single time and then the dom elements in question disappear entirely. Do you have any ideas?
Another tip for the tutorial from the nuxt docs, you may want to change ssr: false
for mode: client.
Note: Since Nuxt.js 2.4, mode has been introduced as option of plugins to specify plugin type, possible value are: client or server. ssr: false will be adapted to mode: 'client' and deprecated in next major release.
ok my issue was a basic one; I am using purgecss and the dynamic AOS css was being removed in the production build!
For the kinds like me seeking for purgecss + aos:
.pipe(purgeCSS({
content: [paths.html.src],
whitelist: ["aos-init", "aos-animate", "data-aos-delay", "data-aos-duration", "fade-(all used)", "fade-(fade types), ...]
}))
You still have to parse either aos.css or _core.scss to get rid of unwanted delay and duration classes.
🍻 Cheers!
ok my issue was a basic one; I am using purgecss and the dynamic AOS css was being removed in the production build!
Can you explain how you solved it? how did you make purgecss leave out AOS?
@afnineone using nuxtjs/purgecss put this in nuxt config.
purgeCSS: { whitelist: [ "aos-init", "aos-animate", "data-aos-delay", "data-aos-duration", "fade-up", "fade-left", "fade-right", "flip-left", ], },
I just had the same issue and solved it by importing aos.css outside of the js file. I added a scss file and added comments for purgecss to ignore aos css :
# assets/css/purgecss.scss
/*! purgecss start ignore */
@import '~aos/dist/aos';
/*! purgecss end ignore */
And then import this custom css either in one of your component, in the plugin, or directly in the css option of nuxt config.
This is what I am using right now. It's based on this article.
import Vue from 'vue';
import AOS from 'aos';
Vue.use(AOS.init({
// your settings here
}));
plugins: [
{
src: '~plugins/aos.js',
ssr: false,
},
]
@import 'aos/dist/aos.css';
I believe that the main difference from other responses from this thread is that I am importing aos.css
on the project stylesheet, instead on the plugin file.
BTW, I saw that @yasminzy response is not importing Vue – like my code. Is that any improvement doing like that?
@afnineone using nuxtjs/purgecss put this in nuxt config.
purgeCSS: { whitelist: [ "aos-init", "aos-animate", "data-aos-delay", "data-aos-duration", "fade-up", "fade-left", "fade-right", "flip-left", ], },
that worked for me, thank you! :)
Nothing helps, animation plays while page is loading, then, when loaded, it stops and element with data-aos is hidden. Tried everything that you guys suggested above. Halp..
Good morning, I have the same problem some solution @maxpodufalov
I think changing the load event works.
// nuxt.config.js
export default {
plugins: [{ src: '~/plugins/aos.js', mode: 'client' }]
}
// plugins/aos.js
import "aos/dist/aos.css";
import AOS from 'aos'
const globalAOS = AOS.init({
// note: your options here
startEvent: 'load'
})
// trigger when the Nuxt page is ready
window.onNuxtReady(() => {
AOS.refresh()
})
export default ({ app }) => {
app.AOS = globalAOS
}
Having same issue. No solution has worked so far
Assalammualaikum mbk. Terimakasih ini keren mbk @yasminzy work 100% di nuxt 2, thanks ya..
Anyone with a solution for Nuxt3
Anyone with a solution for Nuxt3
Having same issue now, and can't find the solution
Anyone with a solution for Nuxt3
@Foddie2 @filipecruz https://nuxt.com/modules/aos should work
Hi, bro! I'm followed your steps with AOS, but not working. Can you help me?