Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to set value for translateX with css in typescript

I am using typescript to set a style of a element dynamically, this is the code looks like:

export function showTranslateButton(e: MouseEvent){
  let translateBtn = document.getElementById("translate-btn");
  if(translateBtn){
    translateBtn.style.width ="40px";  
    translateBtn.style.backgroundColor="red";
    translateBtn.style.height="50px";
    translateBtn.style.transform.translateX=e.pageX;
  }
}

when I set the translateX value, shows error that:

Property 'translateX' does not exist on type 'string'.ts(2339)

what should I do to set the translateX value? I have tried this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

translateBtn.style.transform="translate("+e.pageX+ ","+ e.pageY+")";

it compile success but the style did not add success, the style did not contain the transform block.

>Solution :

I think you should just add "+’px’" add the end of "e.pageX".
Because the value should be a number + the unit (px,rem,precent …)

Tell me if it helps you or not.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading