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

200
Views
Converting Jquery to Javascript(React)

Hi I hope your having a great day, I just got into React and I was trying to convert my old codes to React but the things is my old codes were Jquery and I'm having a hard time on converting it to Vanilla Javascript.

Here's my old code:

function progress() {
    var windowScrollTop = $(window).scrollTop();
    var docHeight = $(document).height();
    var windowHeight = $(window).height();
    var progress = (windowScrollTop / (docHeight - windowHeight)) * 100;

    var bgColor = progress > 99 ? "#fff" : "#fff";
    var textColor = progress > 99 ? "#fff" : "#333";

    $("h1").text(Math.round(progress) + "%").css({ color: textColor });

    $(".fill").height(progress + "%").css({ backgroundColor: bgColor });
}

progress();

What I've done so far:

let progress = () => {
    let windowScrollTop = window.onscroll;
    let docHeight = document.offsetHeight;
    let windowHeight = window.offsetHeight;
    let progress = (windowScrollTop / (docHeight - windowHeight)) * 100;

    let bgColor = progress > 99 ? "#fff" : "#fff";
    let txtColor = progress > 99 ? "#fff" : "#333";      

    document.querySelector("h1").innerHTML = Math.round(progress) + "%";     
    document.querySelector("h1").style.color = bgColor;
            
    document.querySelector(".fill").innerHTML = Math.round(progress) + "%";    
    document.querySelector(".fill").style.color = txtColor;         
}

progress();

Lastly the Math.round() display NaN Screenshot from 2021-11-04 19-06-35

I'm really sorry for all the trouble I hope you could help me with my problem. Thank you

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Upon searching and playing around in the code I finally got an answer

let windowScrollTop = document.documentElement.scrollTop
let docHeight = document.documentElement.offsetHeight   
let windowHeight = window.innerHeight
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!