Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

305
Vistas
How can I make text change when a page is scrolled to a certain point using jQuery?

I am trying to make the content of a div change when the page is scrolled to a certain point using jQuery. Currently, I am trying to accomplish this by adding a class when the page is scrolled past 800 and removing it and adding a different class when the page is above 800. Here is my current code on jsfiddle: https://jsfiddle.net/shgfrdm8/

Here is the jQuery code:

$(window).scroll(function() {
            let windowTop = $(window).scrollTop();
            if (windowTop < 800) {
                $('image-content').addClass('scrolledDown');
                $('image-content').removeClass('scrolledUp');
            } else {
                $('image-content').addClass('scrolledUp');
                $('image-content').removeClass('scrolledDown')
            }
        })

The CSS ids/classes:

.main {
    width: 100%;
    height: 700px;
    overflow: hidden;
    position: relative;
}

.main-image {
    width: 100%;
    position: fixed;
    left: 50%;
    transform: translate(-50%) scale(500%);
}

.filler {
    height: 400vh;
}

.main-text {
    left: -14px;
    width: 99.3vw;
    height: 4000px;
    text-align: center;
    background-color: red;
    position: relative;
}

#image-content::before {
    white-space: pre;
    position: absolute;
    bottom: 20px;
    left: 20px;
    font-family: Impact;
    font-size: 55px;
    font-weight: 550;
    color: white;
    z-index: 4;
    opacity: 1;
    position: fixed;
}

#image-content.scrolledDown::before {
    opacity: 1;
    content: 'ABC';
}

#image-content.scrolledUp::before {
    opacity: 1;
    content: "DEF";
}

The HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="zoom.css">
</head>
<body>

    <div class="image-container">
        <div class="zoom main">
            <img src="images/sourcecode.jpg" class="main-image">
        </div>

        <div id="content-anchor"></div>
        <div id="image-content"></div>
    </div>

    <div class="filler">

    </div>

    <div class="main-text">

    </div>

I am wondering how I can make this work because I far as I can tell the classes either not being added or the classes are not working.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Suggesting the following changes:

$(window).scroll(function() {
  var windowTop = $(window).scrollTop();
  if (windowTop < 800) {
    $('.image-content').addClass('scrolledDown');
    $('.image-content').removeClass('scrolledUp');
  } else {
    $('.image-content').addClass('scrolledUp');
    $('.image-content').removeClass('scrolledDown')
  }
});

This ensures you have the correct Class selector.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda