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

483
Views
JS style.transform translate not responding in CSS

I am trying to link a style.transform = translate to the scroll but it is not working. Other attributes are responding. Would be glad for any support :)

window.addEventListener('scroll', () => {
  let y = 1 + (window.scrollY || window.pageYOffset) / 20;
  y = y < 1 ? 1 : y; // ensure y is always >= 1 (due to Safari's elastic scroll)
    position = '"translate(0,' + '-' + y + 'vh)"'
    
    document.getElementById("marqueeup").style.transform = position;
})
#marqueeup {
width: 200px;
height: 100px;
background-color: red;
}
#placeholder{
width: 100px;
height: 600px;
background-color: blue;
}
<div id="marqueeup"></div>
<div id="placeholder"></div>

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

0

Remove the double quoting.

use position = 'translate(0,' + '-' + y + 'vh)'

Or even better use template literals so

position = `translate(0,-${y}vh)`

window.addEventListener('scroll', () => {
  let y = 1 + (window.scrollY || window.pageYOffset) / 20;
  y = y < 1 ? 1 : y; // ensure y is always >= 1 (due to Safari's elastic scroll)
  const position = `translate(0,-${y}vh)`;

  document.getElementById("marqueeup").style.transform = position;
})
#marqueeup {
  width: 200px;
  height: 100px;
  background-color: red;
}

#placeholder {
  width: 100px;
  height: 600px;
  background-color: blue;
}
<div id="marqueeup"></div>
<div id="placeholder"></div>

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!