Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!