Jump to content
Search Community

scrollTo with vue single file components, how does it work?

Lucas186 test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

hey guys i'm working on an page and want to integrate the scrollTo plugin in the navbar. It's all vue single file components and i dont know how i should write it.

For code pen it's to many components. Example: i want to scroll to an text group which div is named id="wearedifferent".

in the navbar file it is this in the script tag:

<script>
import { Vue, Component } from 'vue-property-decorator';
import { TweenLite } from 'gsap';
 
@Component({})
export default class Navbar extends Vue {
mounted() {
this.scrollTo();
}
destroyed() {
window.removeEventListener('scrollTo', this.scrollTo());
}
 
scrollTo() {
window.addEventListener('scrollTo', () => {
TweenLite.to(this.$refs.weAreDifferent, 1, { scrollTo: '#wearedifferent' });
});
}
}
</script>

 

thats in the template section: 

<b-navbar-nav>
<b-nav-item @click="scrollTo()">Wir sind anders</b-nav-item>
<b-nav-item href="#">Jobs</b-nav-item>
<b-nav-item href="#benefits">Benefits</b-nav-item>
<b-nav-item href="#">Social</b-nav-item>
</b-navbar-nav>

 

first i tried it with href, but its not so smooth like scollTo. could anyone help me?

Link to comment
Share on other sites

It looks like you forgot to import ScrollToPlugin. And you might want to reference it directly in your code somewhere just so your bundler doesn't dump it with tree shaking. 

 

As for the rest of your question, it sounds like maybe it's more Vue-specific but correct me if I'm wrong. We're happy to answer any GSAP-specific questions. I'm personally not familiar with Vue. 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...