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

175
Vistas
Cannot read properties of null (reading 'style') - rotate on scroll troubleshoot

I'm trying to do a rotate-element-on-scroll effect but it seems my JS is wrong. I get the error "(index):271 Uncaught TypeError: Cannot read properties of null (reading 'style')"

My page is jakobnatorp.com

Edit: I've tried replacing "document.querySelector("logoJakob")" with following and it still doesn't work:

document.querySelector(".logoJakob");
document.querySelector("#jakoblogo");
document.getElementByClassName("logoJakob");
document.getElementById("jakoblogo");

HTML

<div class="logojakob" id="jakoblogo" >
<img src="http://jakobnatorp.com/wp-content/uploads/2021/10/cropped-JAKOB-LERCHE-DAA-NATORP.png"/>
    </div>

CSS

.logojakob {
  position: fixed;
  width:150px;
  height:150px;
  margin-top:50px;
  margin-bottom:-300px;
  margin-left:50px;
}

JS

var elem = document.querySelector("logoJakob");
window.addEventListener('scroll', function() {
    var value = window.scrollY * 0.25;
    elem.style.transform = `translatex(-50%) translatey(-50%) rotate(${value}deg)`; 
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

First selector is almost correct, there is only a missing dot and an extra uppercase in querySelector. Pass the class to the querySelector exactly as it is written in CSS

var elem = document.querySelector(".logojakob");
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