Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda