Problem with animated text in CSS

I am facing an issue with the code below. It is supposed to display "Dedicated People" when scrolling down, however, it is not working in my browser. Could it be that I forgot to include a reference in the head section? The code works fine in CodePen, but in other browsers, it is not displaying anything. What could be the reason behind this, and how can I fix it specifically for the Chrome browser?

$(function() {
  var text = $(".text");
  $(window).scroll(function() {
    var scroll = $(window).scrollTop();

    if (scroll >= 10) {
      text.removeClass("hidden");
    } else {
      text.addClass("hidden");
    }
  });
});
@import url('https://fonts.googleapis.com/css?family=Muli:300,400,700');

* {
  margin: 0;
  padding: 0;
}
body {
  background-color: #000;
  height: 200vh;
  font-family: 'Muli', sans-serif;
}
.text {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
  list-style: none;
  border-bottom: 0;
}

.text.hidden {
  border-bottom: 1px solid #fff;
}

.text li {
  display: inline-block;
  float: left;
  font-weight: 700;
  font-size: 2em;
  color: #fff;
  opacity: 1;
  transition: all 0.5s ease-in-out;
  max-width: 2em;
}
.text.hidden li.spaced {
  padding-left: 0;
}
.text li.spaced {
  padding-left: 0.5em;
}

.text.hidden li.ghost {
  opacity: 0;
  max-width: 0;
}
<ul class="text hidden">
  <li>D</li>
  <li class="ghost">e</li>
  <li class="ghost">d</li>
  <li class="ghost">i</li>
  <li class="ghost">c</li>
  <li class="ghost">a</li>
  <li class="ghost">t</li>
  <li class="ghost">e</li>
  <li class="ghost">d</li>
  <li class="spaced">P</li>
  <li class="ghost">e</li>
  <li class="ghost">o</li>
  <li class="ghost">p</li>
  <li class="ghost">l</li>
  <li class="ghost">e</li>
</ul>

Answer №1

Seems like you missed the Jquery script:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Check out this JSFiddle:https://jsfiddle.net/8dc7toLn/

$(function() {
  var text = $(".text");
  $(window).scroll(function() {
    var scroll = $(window).scrollTop();

    if (scroll >= 10) {
      text.removeClass("hidden");
    } else {
      text.addClass("hidden");
    }
  });
});
@import url('https://fonts.googleapis.com/css?family=Muli:300,400,700');

* {
  margin: 0;
  padding: 0;
}
body {
  background-color: #000;
  height: 200vh;
  font-family: 'Muli', sans-serif;
}
.text {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
  list-style: none;
  border-bottom: 0;
}

.text.hidden {
  border-bottom: 1px solid #fff;
}

.text li {
  display: inline-block;
  float: left;
  font-weight: 700;
  font-size: 2em;
  color: #fff;
  opacity: 1;
  transition: all 0.5s ease-in-out;
  max-width: 2em;
}
.text.hidden li.spaced {
  padding-left: 0;
}
.text li.spaced {
  padding-left: 0.5em;
}

.text.hidden li.ghost {
  opacity: 0;
  max-width: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="text hidden">
  <li>D</li>
  <li class="ghost">e</li>
  <li class="ghost">d</li>
  <li class="ghost">i</li>
  <li class="ghost">c</li>
  <li class="ghost">a</li>
  <li class="ghost">t</li>
  <li class="ghost">e</li>
  <li class="ghost">d</li>
  <li class="spaced">P</li>
  <li class="ghost">e</li>
  <li class="ghost">o</li>
  <li class="ghost">p</li>
  <li class="ghost">l</li>
  <li class="ghost">e</li>
</ul>

Answer №2

Your code is functioning perfectly in my browser. Make sure to include jQuery if it's not already included.

For jQuery, visit:

Copy this:

<script
  src="https://code.jquery.com/jquery-3.3.1.min.js"
  integrity="[insert]"
  crossorigin="anonymous">
</script>

and insert it into your document.

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 Jest's moduleNameMapper with Next.js without TypeScript

I've been encountering some challenges trying to implement moduleNameMapper in NextJS using JavaScript. In this particular project, TypeScript is not being utilized. Next: 12.2.5 React: 18.2.0 Jest: 29.0.1 Jest environment jsdom: 29.0.1 Below is the ...

The gradual vanishing of principles

Below you will find text fields that I am populating with values that are later utilized in a JavaScript function. These fields are all contained within a form. The issue I am encountering is that when I submit the form, I initially get the correct value ...

Guide to dynamically updating a textarea in vue.js by incorporating data from several inputs

Is there a way to update a textarea based on multiple inputs using jQuery and vue.js? I have successfully implemented the jQuery part with line breaks, but when I try to display the value of the textarea elsewhere using vue.js, it doesn't seem to work ...

The strict mode in React reveals unexpected changes in state with double rendering

While working with React, I've noticed that it renders twice in Strict mode during development to ensure the function remains pure without any side effects. However, I'm facing some inconsistency in retrieving the state in my case. It seems like ...

Is there a way to optimize downloading multiple identical images using html, css, jquery, etc.?

My chess board features 64 squares, each with a picture of a board piece on either a light or dark square. To ensure proper formatting, a Clear knight is placed on the board. The design utilizes a div element with a background image (representing light or ...

Storing Data with expressjs/session in NodeJS

My development project involves 3 files: app.js, index.js (routes), and Users.js (controller). Upon successful user login (verification between POST data and the database), I aim to store information in a session using expressjs/session. Below is how I c ...

Using THREE.js to incorporate a stroke above extruded text

Looking to enhance text with a horizontal line above it: var geo = new THREE.TextGeometry("x", geometry_options); var mat = new THREE.MeshBasicMaterial({color: 0, side:THREE.DoubleSide}); geo.computeBoundingBox (); var vec = new THREE.Shape(); vec.moveTo( ...

Styling elements with inline-block in IE8

Although there are countless questions addressing this particular issue, allow me to provide more details: The Dilemma The situation is as follows: aside { display: inline-block; } section { display: inline-block; margin-left: 2em; } Here, the eleme ...

Updating text color in JavaFX for a textarea

I'm having trouble getting this to work. After checking the CSS analyzer in the scene builder, it seems that changing the text color in a textarea requires something like this: .text-area .text { -fx-fill: #1e88e5; -fx-font-size: 32px; } How ...

What is the best way to determine the accurate size of a div's content?

There are 2 blocks, and the first one has a click handler that assigns the block's scrollWidth to its width property. There is no padding or borders, but when the property is assigned, one word wraps to the next line. The issue seems to be that scrol ...

Troubleshooting Issue: XMLHttpRequest Incompatibility with Internet Explorer

I'm having an issue with the script below. It works fine on Firefox and Chrome but doesn't seem to work on IE. I've tried various solutions, including lowering the security settings on my browser, but it still won't work. function se ...

HTML Plant with background removed

I have been attempting to create a tree structure similar to the image provided. However, I am encountering difficulty in getting the background stripes to align properly for a specific row. When resizing the browser window, the stripes do not remain fixed ...

The correct way to extract a jwt token from headers and integrate it into an express application

After successfully implementing both the frontend and backend in express.js with authentication and authorization using JWT, I have confirmed that the JWT token is being properly set upon login. You can see the auth-token key in the image below: https://i ...

Achieving the perfect button using a combination of material-ui and styled-components

Utilizing the ToggleButton and ToggleButtonGroup components from material-ui, starting with material-ui's gatsby template. To prevent common material-ui errors with production builds, I am attempting to incorporate styled-components as well. The foll ...

Position a component in relation to another component using AngularJS

Utilizing ng-show and ng-hide, I created a descriptive box that appears below text when clicked. However, there is an issue as the description box does not align directly under the text, similar to what is shown in this image https://i.stack.imgur.com/phBh ...

"Commander.js does not process query strings when used in conjunction with node

I developed a CLI tool using commander.js which has been released on npm. This command-line interface utilizes node-fetch to fetch data from an external API. However, I have received reports from some users stating that the query string in the fetch URL is ...

How can one retrieve the x and y coordinates from the client's browser and pass them to the server in a Bokeh server setup?

I'm currently working on a Bokeh server app called getcoords.py. To start the server, I use the command: bokeh serve getcoords.py. The app includes a HoverTool with a CustomJS callback function and a quad glyph configured to trigger a selected event o ...

On a medium-sized screen, a collapsible button unexpectedly appears amidst the various links

Can anyone help me with sorting out the order of navbar elements? I'm facing an issue where on small screens, the collapse button appears above the links, but on medium screens, it shows up before the last link in the menu. Any suggestions on how to f ...

Utilizing various directives with distinct scopes for a single element

Is it possible for an element to have multiple directives with their own unique scopes? For example, let's consider a custom directive's child element with the controller's scope along with another directive (such as "ng-class"): <custo ...

When redirecting to the same component, Vue.js hooks are not triggered

In my Vuejs project, I have two pages located at the same level with a common component. However, when I redirect from post/new to post/edit/:id, the beforeMount method is not being called. redirect() { this.$router.push({path: `home/post/edit/${this ...