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

240
Views
Transforming CSS with Pure JavaScript not Work

I tried to transform my div with javascript after getting element by IDs. But i got nothing, it doesn't works.

Here is my code :

const sliderA = document.getElementById("obSlideTop1");
const sliderB = document.getElementById("obSlideTop2");
const flame = document.getElementById("THST");
flame.addEventListener('mouseover', () => {
  sliderA.style.transform = "translate(-3vw, -343vh);"

  sliderB.style.transform = "translate(3vw, -343vh);"
})

But when i tried to styling with something else like .backgroundColor or .opacity, it still works with them. object.style.transform is the only thing that have problem with me.

const sliderA = document.getElementById("obSlideTop1");
const sliderB = document.getElementById("obSlideTop2");
const flame = document.getElementById("THST");
flame.addEventListener('mouseover', () => {
  sliderA.style.transform = "translate(-3vw, -343vh);"
  sliderA.style.backgroundColor = "rgb(124, 1, 124)";
  sliderA.style.opacity = ".5"

  sliderB.style.transform = "translate(3vw, -343vh);"
  sliderB.style.backgroundColor = "rgb(233, 33, 33)";
  sliderB.style.opacity = ".5";

  console.log(sliderA,sliderB)
})

it have console output :

<div id="obSlideTop1" style="background-color: rgb(124, 1, 124); opacity: 0.5;"></div> 
<div id="obSlideTop2" style="background-color: rgb(233, 33, 33); opacity: 0.5;"></div>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It's because "translate(-3vw, -343vh);" is an invalid value for a transform because of the semi-colon ; inside of the string.

const sliderA = document.getElementById("obSlideTop1");
const sliderB = document.getElementById("obSlideTop2");
const flame = document.getElementById("THST");
flame.addEventListener('mouseover', () => {
  sliderA.style.transform = "translate(-3vw, -343vh)";
  sliderA.style.backgroundColor = "rgb(124, 1, 124)";
  sliderA.style.opacity = ".5"

  sliderB.style.transform = "translate(3vw, -343vh)";
  sliderB.style.backgroundColor = "rgb(233, 33, 33)";
  sliderB.style.opacity = ".5";

  console.log(sliderA,sliderB)
})
<div id="obSlideTop1" style="background-color: rgb(124, 1, 124); opacity: 0.5;"></div> 
<div id="obSlideTop2" style="background-color: rgb(233, 33, 33); opacity: 0.5;"></div>
<button id="THST">flame</button>

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!