Intersection Observer is functioning properly as elements vanish once they finish appearing

New to this forum and looking forward to receiving assistance and making some fantastic connections!

Currently working on my personal portfolio with the goal of getting it online for job hunting purposes, but encountering some challenges along the way.

The layout I'm aiming for is a single-page portfolio where elements fade in as you scroll, which I've managed to achieve. However, once the fading is complete, the elements disappear abruptly.

Has anyone else faced this issue before? Do I need to include a fadeOut option in my CSS to address the sudden disappearance of the elements, which are structured in sections?

Also, utilizing Bootstrap in my project as well!!!!!

Code provided below:

CSS
 
h1 {
  font-size: 4rem;
}

h2, h3, h4, h5, h6 {
  font-size: 3em;
}

p {
  font-size: 1.5em;
}

hr {
  border-top: 5px dotted white;
}

body {
  background-image: linear-gradient(rgba(0, 0, 0, 0.5,
        rgba(0, 0, 0, 0.5)), url(https://i.pinimg.com/originals/16/5a/ca/165aca25ea0a632a7eddae4230003f17.jpg);
  background-repeat: no-repeat;
  background-attachment: fixed;
}

/* Header Section */
...
...

JavaScript

const sectionOne = document.querySelector('#header');
const sections = document.querySelectorAll('section');

const options = {
  root: null,
  threshold: 0,
  rootMargin: "250px"
};

const observer = new IntersectionObserver(function(entries, observer) {
entries.forEach(entry => {
  if (!entry.isIntersecting) {
    return;
  }

  entry.target.classList.toggle('fade');

  console.log(entry.target);

})
}, options);

sections.forEach(section => {
  observer.observe(section);
})

Answer №1

Is this the solution?

.appear {
  animation: appearIn ease 3s forwards;
  -webkit-animation: appearIn ease 3s forwards;
  -moz-animation: appearIn ease 3s forwards;
  -o-animation: appearIn ease 3s forwards;
  -ms-animation: appearIn ease 3s forwards;
}

Source: Keeping the final state at the end of a CSS3 animation

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

The caching mechanism in IE 11 is preventing Ajax from loading and displaying data

Utilizing Ajax to verify data and display it on the page, alongside implementing varnish cache. The data appears correctly on all web browsers, with the exception of IE 11, unless the varnish cache is disabled. function checkMyData() { var surl = 'in ...

dynamic text overlay on a bootstrap carousel

Having limited knowledge in html and css, I am using a bootstrap carousel slider with text. I am trying to change the color of the box randomly. https://i.sstatic.net/TozUP.jpg Here is the code that I am currently using: <ol class="carousel-indicato ...

Link PayPal payments to the individual making the payment

On my website, I offer in-game features that can be purchased through a miniature store with PayPal buy now buttons. I'm looking for the best and most secure method to automatically deliver these in-game bonuses to users after they have completed thei ...

Deactivate the dropdown menu without triggering any event

I am working on a JSP page and I need to find a way to disable a dropdown list without using an onclick method or event in the dropdown menu itself. <% boolean condition = true; if(condition){ // Here, I need to access 'plc1' ...

The variation in CSS output between Google Chrome on Windows and Ubuntu

My code includes a div tag: <a href="#"><div class="field btn half green" id="register-btn">Register</div></a> Here is the CSS code for the tag: .field { position: absolute; width: 205px; left: 22px; color: #eaeae ...

Are items placed into an array passed by reference or by value?

When working with custom Objects in an Angular context, I define two objects "a" and "b" using an interface. These are created as class attributes along with an empty array of these objects. public a: CustomObj; public b: CustomObj; public array: ...

How to build a unique ajax call function using a single object parameter in jQuery and JavaScript

Can someone provide a code example for the following requirements: A custom JavaScript function that takes a single object as its argument Utilizes jQuery's ajax method to make an AJAX call The object argument must specify all possible values that c ...

Switch the background image of one div when hovering over a different div

Can anyone assist me with creating an interactive map where continents light up as you hover over them? I am using multiple images within div elements in order to achieve this effect. Specifically, I want to change the background image of one div when hove ...

The OTP submission in Phone Email's phone authentication using Node JS did not result in the reception of the token

I have implemented the “Login with Phone” Button from Phone Email on my Node JS website. The button opens a popup to enter the mobile number and then displays an OTP window after submission. Although I receive the OTP SMS and enter it successfully, I a ...

A step-by-step guide on accessing an expressjs endpoint from a static html file using Vercel

I am working on a basic app that consists of one server named /api/index.js and one file called index.html located at the root. In the index.js file, there is a route defined as app.get("/api/mystuff", () => {...}) The index.html file makes a request ...

method that provides route-specific variable outputs

I have a situation where multiple routes require the same userdata from the database. Although I have a function to verify if the user is logged in, this function does not return the user variables. Here is an example route: app.get('/template', ...

What is the best way to utilize AJAX for uploading .mp4, .mp3, and .doc files together with additional FormData?

Hello everyone, I have been successfully uploading files (documents and images) using AJAX. However, I am facing some challenges when it comes to uploading videos through AJAX. I have searched extensively on this site for solutions but have not found exact ...

Display issue with ThreeJS cube

Currently, I'm delving into the world of ThreeJS and decided to incorporate the library into my existing NextJS project. My goal was simple - to display a cube on the front page. However, despite my best efforts, nothing seems to be appearing on the s ...

The first argument in the Node.appendChild function does not adhere to the Node interface when trying to append to a new element

Hey there, I'm new to web development and could use some help. I'm encountering an error where I am trying to add an href attribute to an image tag. Here is my code: function linkus() { var a = document.getElementsByTagName("img"); ...

The float right attribute doesn't stay contained within the box; instead, it drifts outside the box

I've been struggling to keep this box fixed at the top of the browser, but I'm facing an issue with the positioning on the right side. I can't seem to figure out how to solve it, so I'm reaching out for some help. #StickyBar #RightSide ...

Setting headers in Node.js after they have already been sent to the client is not allowed

I'm currently enrolled in a node.js course on Udemy which seems to be outdated. I've encountered some errors that I'm struggling to resolve. Here's what I've tried so far: using next(); adding return res inside all if statements ...

A guide to updating a particular row and sending parameters with jQuery and AJAX

I am utilizing a JSON response to dynamically display table content. Here is the code I am using to display row values: var rows = ''; for(var i=0; i<response.response.length; i++) { rows += '<tr><td class="country">&ap ...

Definition for TypeScript for an individual JavaScript document

I am currently attempting to integrate an Ionic2 app within a Movilizer HTML5 view. To facilitate communication between the Movilizer container client and the Ionic2 app, it is crucial to incorporate a plugins/Movilizer.js file. The functionality of this f ...

experiencing difficulty with a background image that is failing to display

I'm having a hard time getting my background-image to show, even though I know it should be an easy fix. Here's the code for the div class where I want the background to display: .sun-face{ background-image: url("./images/Sun_face.svg"); } ...

The Typescript counterpart to PropTypes.oneOf, utilizing a pre-existing variable

While I know this question has been addressed on Stack Overflow here, I still find myself struggling with a similar issue in my TypeScript project. Currently, I am in the process of converting a JavaScript project to Typescript. Within one of my React com ...