Execute the setTimeout function when scrolling occurs

I need help delaying a timeout effect. Currently, the effect begins as soon as the page loads, but I want it to start when I scroll to a specific div. You can see how it currently functions here.

After some research, I came across a library called waypoint that allows triggering events based on waypoints using the code below. However, I have not had any success in implementing it. I also tried setting the display property to none and changing it once the CSS animation was triggered, but when it appeared on the page, the progress bars were already in place.

 var waypoint = new Waypoint({
  element: document.getElementById('waypoint'),
  handler: function(direction) {
    console.log('Scrolled to waypoint!')
  }
})

Answer №1

Here is the JSFiddle link where you can view my solution: https://jsfiddle.net/ab1cde2f/9/

I made some changes in the CSS by converting certain ID's into classes. In the Javascript section, I performed the following actions:

$(document).ready(function () {
    $('#startAnimation').waypoint(function () {
        setTimeout(function () {
            $('#progress-html').addClass('progress-html-class');
        }, 2800);

        setTimeout(function () {
            $('#progress-css').addClass('progress-css-class');
        }, 3500);

        setTimeout(function () {
            $('#progress-javascript').addClass('progress-javascript-class');
        }, 4200);

        setTimeout(function () {
            $('#progress-php').addClass('progress-php-class');
        }, 4900);

        setTimeout(function () {
            $('#progress-angular').addClass('progress-angular-class');
        }, 5600);
    });
});

In simple terms, with the help of JQuery, I set a waypoint to trigger animations when it reaches a specific row (identified by the id #startAnimation). Upon reaching this point, timeouts are used with different delays to add the required css classes which initiate the animations.

If you're unclear about any part of my implementation, feel free to ask for clarification.

Answer №2

By utilizing a JavaScript function called onscroll(), you can create a smooth animation effect on your website. Simply assign the onscroll function to the div element and implement animations using setTimeout() and clearTimeout(). The onscroll() event function will continuously trigger the animation until it reaches the specified target div, at which point it will come to a halt.

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

Exploring the combination of Babel and Next.js: Integrating custom scripts into a project

Hello, I am currently learning next.js and facing a common issue that I need help with. I have created my own ES6 JavaScript library and now I want to convert it to babel so I can use it in my next.js application. Is there a way to configure babel for sp ...

The border bottom effect in Hover.css is malfunctioning when used in the Opera browser

I've implemented a hover effect using hover.css that works perfectly in all browsers except Opera. Surprisingly, the effect only seems to work in Opera when I remove the following properties: -webkit-transform: perspective(1px) translateZ(0); transf ...

The functionality of the dynamic drag and drop form builder is not functioning as expected in Angular 12

I am currently developing a dynamic form builder using Angular version 12. To achieve this, I decided to utilize the Angular-Formio package. After installing the package and following the steps outlined in the documentation, I encountered an issue. The i ...

What method can be used to verify if Handlebar.js is integrated into the application?

I am struggling to verify the presence of Handlebar JS on the application's HTML page. No matter what I do, it keeps throwing an error saying "Uncaught Reference Error - Handlebars is not defined". Can anyone provide guidance on how to fulfill this ta ...

Sending mass text messages with a customized message for each phone number - A guide using Twilio

I have a batch of 100 to 1500 phone numbers that I need to send SMS messages to. Each message should include the recipient's name associated with the phone number in the text. How can I achieve this using Twilio? client.notify.services(notifyServiceS ...

Cancel the use of the $.each method when the specified variable is located

Currently, I am utilizing a $.each method to search through a JSON in order to find a specific variable. Here is the code snippet I am working with: $.each(heroes_json.heroes, function(key, val){ if(val.id == hero){ hero = val.localized_name; ...

What could possibly be the issue here? The error message I received is: "Error: INSERT INTO.... Unknown column 'jon' in 'field list'"

When attempting to input form data into my database, I encountered two distinct errors. Initially, an error related to SQL syntax appeared: "Error: INSERT INTO movie (firstname, surname, phonenumber, email, movie, session, day) values(jon, doe, <a href ...

Implementing file change detection using view model in Angular

When using the input type file to open a file and trigger a function on change, you can do it like this: <input type="file" multiple="multiple" class="fileUpload" onchange="angular.element(this).scope().fileOpened(this)" /> The functi ...

Permission denied: Node.js bash was trying to access /usr/local/bin/node, but was unable

I've been working on setting up Node.js on my Ubuntu machine. I carefully followed the step-by-step instructions provided by the official documentation: ./configure && make && sudo make install After following the steps, I was able t ...

Having trouble with aligning the Bootstrap grid in the center? Something seems to be off

I'm currently working on a project for Free Code Camp, but have encountered an issue. I am struggling to center the paragraph text below the image properly. The grid is set to 4 in this case. <div class="container"> <div class="row"> ...

Having trouble with clearTimeout and clearInterval functions not functioning properly?

Currently, I've set up a countdown using both setInterval and setTimeout functionalities, and it seems to be running smoothly. However, I encounter an issue when trying to stop the countdown upon clicking a certain button; it pauses only after complet ...

Guidelines for redirecting to ensure the presence of an HTML page within a directory URL

In my folder named /topicA/, I have various subtopics like /topicA/subtopic1.html, /topicA/subtopic2.html, and /topicA/subtopic3.html. I also wanted to create a /topicA.html page, but I'm having trouble getting the .htaccess file to function properly ...

Unlocking Fields in SharePoint 2007: A Step-by-Step Guide to Enabling a Disabled Field with Checkbox Activation

Hey there! I'm curious to find out what I might be overlooking... function executeMe(){ if(document.getElementById("ctl00_m_g_ef941f4a_7f2d_4a75_a119_6f009e7a22ad_ctl00_ctl04_ctl04_ctl00_ctl00_ctl04_ctl00_ctl00").checked{ document.getElementById("c ...

Scanning the header of panel groups for information

I'm currently working on developing a custom search engine to navigate through the panel-group that I've created, but I seem to be struggling with selecting the correct elements. The structure of my generated Markup is as follows: <div id="o ...

The jQuery UI Tabs Ajax feature seems to only be displaying content in the first tab that is

My jQuery UI tabs are set up to load their content using the ajax method: <div id="tabs"> <ul> <li><a href="/messages/inbox" title="Inbox"><span>Inbox</span></a></li> <li><a href ...

Tips for building a modal box with HTML, CSS, and jquery!

Looking to create a modal box using HTML, CSS, and jQuery? <button id="myBtn">Click here to open the Modal</button> This code will help you achieve that: <!-- This is the Modal content --> <div class="modal-content"> <sp ...

Confused in the world of .net and jQuery

I've come across similar questions on this topic before, and there are several resources available. However, I'm still feeling pretty lost and unsure about the next steps. My situation involves a textarea that contains data I need to send to a s ...

"Troubleshooting: Why isn't the ParamQuery Jquery Grid plugin showing

I have a specific requirement to present data in a grid format with pagination, and it will be read-only, so no editing functionality is needed. After exploring various plugins, I came across the ParamQuery Grid from jQuery which seems to fit my needs perf ...

Determining the client web app version in HTTP requests

We frequently update our single page application, but sometimes an older version with a bug can still be in use. It would be helpful if the client could include a version identifier with requests to let us know which code base is being used. Are there est ...

Angular: searcher function behaves differently based on the type of data being filtered

Can you quickly check out these two examples and tell me why one is working while the other isn't? Here is the first example with real json data extracted from my app, which is not working: http://plnkr.co/edit/2Z5SMlANCGd3r4Trfwzm?p=preview And her ...