A common inquiry regarding Vue: How to effectively incorporate fullpage.js wrapper with additional functionalities

Having recently delved into Vue, I am currently tackling a project that involves the Fullpage.js Vue wrapper. While I have successfully implemented the Fullpage functionality, integrating additional features like an animation-on-scroll function has proven to be challenging. I came across this basic animation-on-scroll function in a CodePen example, and attempted to incorporate it into my project without success.

The issue lies in the implementation of the handleScroll() method along with the v-on directive on the h2 element to add a class upon scrolling. Despite defining the necessary template code, which includes conditional classes based on scroll position, the scrolled property fails to update appropriately.

<template>
    <full-page ref="fullpage" :options="options" id="fullpage">
        <div class="section">
            <h3 :class="{'bounceInLeft': scrolled}" v-on="handleScroll" class="animated">{{scrolled}}</h3>
        </div>
        <div class="section">
            <div class="slide">
                <h3>Slide 2.1</h3>
            </div>
            <div class="slide''>
                <h3>Slide 2.2</h3>
            </div>
            <div class="slide">
                <h3>Slide 2.3</h3>
            </div>
        </div>
       <div class="section">
            <h3> ;Section 3</h3> ;
        < ;/div> ;
   </full-page>
< /template>

To rectify this issue, I defined the Vue instance to include options for the Fullpage component, as well as the scrolling animation methods and the scrolled data property:

// create vue instance w/ fullpage
new Vue({
    el: '#app',
    data() {
     return {
         scrolled: false,
         options: {
             navigation: true,
             menu: '#nav-menu',
             anchors: ['page1', 'page2', 'page3'],
             sectionsColor: ['#41b883', '#ff5f45', '#0798ec', '#fec401', '#1bcee6', '#ee1a59', '#2c3e4f', '#ba5be9', '#b4b8ab']
            },
          }
     },
     methods: {
          handleScroll() {
                 let obj = document.querySelector('h3');
                  let {top, bottom} => obj.getBoundingClientRect();
                   let height = document.documentElement.clientHeight;
                     this.scrolled = top < height && bottom >0;
                   }
               },
    created() {
      window.addEventListener('scroll', this.handleScroll);
    },
    destroyed() {
        window.removeEventListener('scroll', this.handleScroll);
    }
});
 

Despite my efforts, the value of the scrolled property remains static at false and doesn't reflect changes during scrolling. Any guidance on how to properly update this value and apply the desired class would be greatly appreciated. Feel free to seek clarification if needed. Thank you!

Answer №1

It is my understanding that the objective is to dynamically apply the bounceInLeft class when a section comes into view. To achieve this, tracking each section individually is necessary. The boolean variable 'scrolled' has been expanded into an object with properties corresponding to the sections - in this scenario: page1, page2, page3.

<h3 :class="{'bounceInLeft': scrolled.page1}" class="animated">{{scrolled.page1}}</h3>

Subsequently, include the 'scrolled' object in your data and utilize the 'afterLoad' callback to modify the appropriate scrolled page boolean.

new Vue({
    el: "#app",
    data: function() {
        return {
            scrolled: {
                page1: false,
                page2: false,
                page3: false
            },
            options: {
                licenseKey: null,
                afterLoad: this.afterLoad,
                navigation: true,
                anchors: ["page1", "page2", "page3"],
                sectionsColor: ["#41b883", "#ff5f45", "#0798ec"]
            }
        };
    },
    methods: {
        afterLoad: function(origin, destination, direction) {
            const { top, bottom } = destination.item.getBoundingClientRect();
            const height = document.documentElement.clientHeight;
            this.scrolled[destination.anchor] = top < height && bottom > 0;
        }
    }
});

https://codepen.io/RichardAyotte/pen/axpKoQ

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

AngularJS tips for resolving an issue when trying to add duplicates of a string to an array

Currently dealing with a bug that occurs when attempting to push the same string into an array that has already been added. The app becomes stuck and prevents the addition of another string. How can I prevent the repeat from causing the app to get stuck w ...

React - Render an element to display two neighboring <tr> tags

I'm in the process of creating a table where each row is immediately followed by an "expander" row that is initially hidden. The goal is to have clicking on any row toggle the visibility of the next row. To me, it makes sense to consider these row pa ...

Multer's re.file function is returning an undefined value

I am seeking assistance with my coding project. I have a setup that uses React on the front end, Node.js on the backend, and MySQL as the database. The issue I am facing is related to file transfer using Multer in Node.js. When trying to transfer files, Mu ...

Issues with monitoring multi-touch gesture events using Hammer JS

Can anyone figure out why this code, which utilizes hammer.js for multi-touch gesture events, is not functioning as expected? This code closely resembles one of the examples on Hammer's documentation. Despite setting up swipe events on specific elem ...

Finding out which carousel the user is currently engaging with in the Slick Carousel can be accomplished by following these steps

I am struggling with applying a class to the carousel container when the first slide is active in a page that contains multiple Slick carousels. Is there a way to update the code below so that the class is only applied to the specific carousel the user is ...

Can a <Link> be customized with a specific condition?

On the webpage, there is a list of elements retrieved from a database. When clicking on the last displayed element, I want to link to '/upload' if it shows "Carica Referto", or link to '/consensi/{this.$state.item.hash_consenso}' if it ...

Unable to retrieve information from the database during the http.get request

Hey everyone, I've encountered an issue that I need help with. I'm working on retrieving data from a database using an HTTP call and then returning it to the front end. Here's what I have so far: app.get('/contentHandler/post/frontPage ...

I am experiencing an issue with my Nuxt + Tailwind setup where my custom tailwind.config.js file is not being applied, and the

After carefully following the official Tailwind + Nuxt documentation to integrate Tailwind into Nuxt, I successfully implemented it in 2 new projects and one existing Nuxt project. Unfortunately, I am facing an issue with the existing Nuxt project. The ex ...

Action creator incomplete when route changes

In my React-Redux application, there is an action creator that needs to make 4 server calls. The first three calls are asynchronous and the fourth call depends on the response of the third call. However, if a user changes the route before the response of t ...

Turning a JavaScript function into jQuery

Is there a way to convert this JavaScript selected code into jQuery? I need to target a button class instead of an ID, and I've heard that using jQuery is the simplest way to achieve this. var playButton1 = $('.playButton1'); playButton1.o ...

ASP.NET repeater causing jQuery scrollTop to malfunction after first use

I am facing a peculiar issue where I need to scroll through repeater items in a RadWindow using arrow keys in an ASP.NET application. Below is the code snippet: function isScrolledIntoView(elem) { var docViewTop; var docViewBottom ...

Can an action be activated when the mouse comes to a halt?

Currently, I am having trouble triggering an event when a user stops moving their mouse over a div element. The current event is set up to show and follow another element along with the mouse movement, but I want it to only display when the mouse stops mov ...

Modify the appearance of a specific side of a CircleGeometry shape over a set period of time

As a novice in the world of Three.js, I recently completed a crash course and now have a basic understanding of its capabilities. I managed to create a rotating disc on my website with my own image/texture, but I would like to change the texture/image on ...

Obtain a specific text value as a variable using Google Tag Manager

In my quest to extract the dynamic "sku" value from GTM, I am faced with a challenge. This particular value is unique for each product page. Below is an example of how the code appears on the page: <script type="application/ld+json"> { "@context" ...

completed() versus finished()

As I was going through the documentation for passport, I came across an interesting observation regarding the use of serialize() and deserialize(). It seems that done() is called without being explicitly returned in one scenario. However, while setting up ...

Automating user login with node.js and passport.js: A step-by-step guide

My login application is built using node.js and passport.js, with the session being maintained using express-session and connect-mongo. I need to ensure that users are redirected to the home page upon accessing the URL, only sending them to the login page ...

What is V8's approach to managing dictionaries?

After attending V8 presentations, it became clear to me that it optimizes constructions such as the one below by tagging a type object: function Point(x, y) { this.x = x; this.y = y; } I am curious about what happens if I were to return an object (JS ...

Background image specifically for the Fullcalendar sun component

When setting a background image for Sunday in the month view, I noticed that the day "Sunday" in the header is also getting the same background. The CSS for the table thread has classes like .fc-sun and .fc-mon set as well, but I'm not sure how to rem ...

transferring data from JavaScript on the client side to Express on the server side

Using JavaScript, I have created the HTML DOM that you see in the code below. Now, my goal is to send the value of an input created in JavaScript to the server side. The server is built with node.js and express framework. Once the value is sent to the serv ...

Efficiently loading images asynchronously for smooth execution of JavaScript using Splide. Resolving Largest Contentful Paint (LCP) issue specifically on mobile

My webpage features a carousel of images at the top, created with Splide. However, I have noticed that my LCP score is significantly lower on mobile devices compared to desktop. The culprit seems to be in the Load Delay section: Time to first byte (TTFB) ...