Activate the scroll bar once the timer has finished counting down

Can someone assist me with enabling the scrollbar on my website after a certain duration of an intro? I'm struggling with figuring out how to do this. Below is the code snippet I have so far:


                let intro = document.querySelector('.intro');
                let logo = document.querySelector('.logo');
                let logoSpan = document.querySelectorAll('.logo-parts');

                window.addEventListener('DOMContentLoaded', () => {

                    setTimeout(() => {
                        logoSpan.forEach((span, index) => {
                            setTimeout(() => {
                                span.classList.add('active');
                            }, (index + 1) * 100);
                        });

                        setTimeout(() => {
                            logoSpan.forEach((span, index) => {
                                setTimeout(() => {
                                    span.classList.remove('active');
                                    span.classList.add('fade');
                                }, (span + 1) * 50);
                            });
                        }, 2500);

                        setTimeout(() => {
                            intro.style.top = '-100vh';
                        }, 2500);

                    });

                });
            
<div class="logo">Logo <span class="logo-parts">parts</span></div><div class="intro">Intro</div>

Answer №1

let introEl = document.querySelector('.intro');
let logoEl = document.querySelector('.logo');
let logoSpanEls = document.querySelectorAll('.logo-parts');

window.addEventListener('DOMContentLoaded', () => {
  
  
  // Code remains unchanged below:
  setTimeout(() => {
    logoSpanEls.forEach((span, index) => {
      setTimeout(() => {
        span.classList.add('active');
      }, (index + 1) * 100);
    });

    setTimeout(() => {
      logoSpanEls.forEach((span, index) => {
        setTimeout(() => {
          span.classList.remove('active');
          span.classList.add('fade');
        }, (span + 1) * 50);
      });
    }, 2500);

    setTimeout(() => {
      introEl.style.top = '-100vh';
    }, 2500);
    
    // Additional code inserted:
    document.body.style.overflow = "hidden";
    setTimeout(() => {
      document.body.style.overflow = "";
    }, 2500);
  });
});
<div class="logo">Logo <span class="logo-parts">parts</span></div>

<div class="intro">
  Intro
  <br><br> Dummy text so this works:
  <br><br> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi volutpat enim vitae sapien consequat tincidunt. Integer luctus maximus lacinia. Vivamus efficitur varius sagittis. In accumsan, augue nec imperdiet dignissim, lacus tellus tincidunt
  felis, non viverra erat magna rutrum libero. Nam ut vehicula lectus, sed bibendum sapien. Suspendisse pulvinar urna id euismod hendrerit. Aliquam id commodo neque, eget tempus justo. Donec pulvinar mi non nunc pretium tempus. Nunc vitae mauris non elit
  cursus rutrum vel ut eros. Vestibulum tempus enim lacus, nec finibus nunc dapibus at. Sed eu malesuada erat. Nulla posuere dolor at hendrerit sodales ... [truncated for brevity]</answer1>
<exanswer1><div class="answer accepted" i="73442560" l="4.6" c="1661147098" a="YXNkZjQuMTUxNTg=" ai="15478935">
<p><div>
<div>
<pre class="lang-js"><code>const introductionVar = document.querySelector('.intro-div');
const logoElementVar = document.querySelector('.brand-logo');
const logoParts = document.querySelectorAll('.logo-sections');

window.addEventListener('DOMContentLoaded', () => {
  
  
  // This part is left as is:
  setTimeout(() => {
    logoParts.forEach((part, index) => {
      setTimeout(() => {
        part.classList.add('active-part');
      }, (index + 1) * 100);
    });

    setTimeout(() => {
      logoParts.forEach((part, index) => {
        setTimeout(() => {
          part.classList.remove('active-part');
          part.classList.add('fading-part');
        }, (part + 1) * 50);
      });
    }, 2500);

    setTimeout(() => {
      introductionVar.style.top = '-100vh';
    }, 2500);
    
    // The following lines were added:
    document.body.style.overflow = "hidden";
    setTimeout(() => {
      document.body.style.overflow = "";
    }, 2500);
  });
});
<div class="brand-logo">Brand Logo <span class="logo-sections">sections</span></div>

<div class="intro-div">
  Introduction
  <br><br> Placeholder text to make things work properly:
  <br><br> More content goes here lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut ornare mauris vel condimentum feugiat. Maecenas ante turpis, congue quis facilisis non, fermentum et est. Curabitur vestibulum venenatis eros, in semper
  ex blandit ac. Quisque sed velit sagittis, laoreet purus sit amet, sollicitudin tortor. Ut interdum leo vel mi suscipit, et faucibus magna convallis.
</div>

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

Using the result of one function in another function when using async await

I am facing an issue with running a function based on the return value of another function: // in utils.js methods:{ funcOne(){ // do some thing return true } } //in component.vue methods:{ funcTwo(){ let x = this.funcOne() if(x){ ...

Reasons for dividing by 1 in JavaScript

While completing a basic programming assignment from my teacher, I encountered an interesting issue in Javascript. I found that when dividing a number by 1, it returns an unexpected value. Can anyone provide an explanation for this? I have created a jsfidd ...

Can you explain the contrast between onsubmit="submitForm();" and onsubmit="return submitForm();"?

Is it possible that the form below is causing double submissions? <form name="myForm" action="demo_form.asp" onsubmit="submitForm();" method="post"> function submitForm(){ document.myForm.submit(); } I've noticed a bug where sometimes two ...

Building a dynamic search feature using Ajax and PHP to transfer search results to a PHP variable or display as plain text

I designed a form that allows users to input orders with various details into the database. One of the fields in this form is labeled Client, where users have the option to either create a new client or select an existing one. To facilitate the selection ...

An effective method for retrieving textarea data in Node.js

I am facing an issue where I cannot successfully send data from a <textarea> to Node.js. It seems that the data I'm trying to send is not being received by Node.js. To retrieve data in Node.js: continueBtn.addEventListener("click", ...

Issue when attempting to update the background image using d3.js in browsers other than Firefox

I am experiencing a strange error that is puzzling to me. What I have done is placed a background image (SVG file) in a div using CSS. This SVG is used to create a Sprite animation, which is functioning correctly. .runner { background: url("0804_ ...

Managing stream pauses and resumes in Node.js using setTimeout()

After some experimentation with Node.js (v4.4.7), I managed to create a simple program to play a sound... const Speaker = require('audio-speaker/stream'); const Generator = require('audio-generator/stream'); const speaker = new Speake ...

Using Grails, the event listener can be triggered by a change in the

Looking for some advice on implementing a dynamic textfield element in a Grails form. I'm using the remoteFunction action to call a template, but unfortunately, the template is not being called as expected. When I switch from "g:textField" to "g:selec ...

Updates to mousetrap key bindings are being reflected in the $scope object, but are not being detected by the

I have developed a function that updates a scope variable as shown below: // controller.js $scope.variable = 0; $scope.$watch('variable', function(){ console.log("change from watch"); }); $scope.increment = function(){ $scope.variable++; ...

Executing a Node.js script using an absolute path

In the process of developing a basic app using Node.js and Express, I've encountered an issue. The script is located at path/to/script/server.js. When I run this script with node server.js while in the correct directory, everything functions correctly ...

Passing form data to PHP using AJAX in CodeIgniter Framework

I'm facing an issue with my HTML structure which is as follows: <form method="POST"> Name : <input id="asgname" type="text"> <br> Description : <input id="asgdescription" type="text"> <br> <a href="#" id=" ...

What is the best method for utilizing dynamically assigned keys within a JSON object?

I am currently working with Rhino and I need to find a way to utilize a variable in order to define the key of a map. Here's an example of what I'm trying to achieve: var name = "Ryan"; var relationshipType = "brother"; var relatedName = "David" ...

Displaying an HTML string on a webpage

I am developing a user dashboard using Django for a Python-based web application. This web application generates emails, and the HTML content of these emails is stored in a file (and potentially in a database table as well). As part of the dashboard's ...

Position the text alongside the thumbnail rather than in the center

In the current setup, my username text is positioned in the center of the view. I want to reconfigure it so that it displays directly to the right of the thumbnail. However, removing the alignItems: 'center', property from the item disrupts the e ...

Using Thymeleaf in a Spring Boot application, the modal automatically closes after submission

How can I keep the modal open when I click the submit button? I want to reload an existing modal form when I click submit. The code form is in fragment/header, and when I click the "login" button, the modal shows up. The issue is that in views/loginForm, ...

Having difficulty loading the JSON configuration file with nconf

I'm currently attempting to utilize nconf for loading a configuration json file following the example provided at: https://www.npmjs.com/package/nconf My objective is to fetch the configuration values from the json file using nconf, however, I am enc ...

"Exploring the integration of video.js with React Hooks: A step-by-step

I have been utilizing video.js within the React framework and am now looking to transition to React Hooks. The current version of my React project is 16.8.3 Below is the initial functioning code: import React, { PureComponent } from 'react'; i ...

Utilizing Server-Sent Events to display a interactive navigation button

Currently, I am managing a web-based point of sale system where some buttons are hidden for specific functions. To streamline the process, I would like to allow managers to simply click on an "Enable" button in the admin panel and have it immediately refle ...

provide a hyperlink to the icon located in front of the navigation bar

I'm struggling to come up with a suitable title for this issue. What I am trying to achieve is placing a small icon in front of the navbar so that visitors can click on it and be directed to another site. Initially, I attempted to place the icon using ...

Exploring unique forms with the turfjs polygon difference() function

While implementing the difference() function for my polygon map, I encountered a problem where unexpected shapes would appear or disappear when zooming in on the map. These shapes should not be there. The polygons involved are of type MultyPolygon and Poly ...