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

119
Views
jQuery css transform translate3d does not keep percentage precision

I want to apply inline styling transform: translate3D(...) to an element with jQuery's css(), but when using a percentage for the translation it cuts off the precision to 3 decimals.

Example

Let's say I have the following element.

<div class="sliderContent"></div>

And I want to apply a translation with a specific percentage based on amount of visible elements (6), which should lead to an offset of -116.66666666666667% (minus due to translation to the left).

let sliderContent = $('.sliderContent');

let visibleSliderItems = 6;
let transformOffset = 100 + (100 / visibleSliderItems);
let translate3D = 'translate3d(-' + transformOffset + '%, 0px, 0px)';

console.log(translate3D); // translate3d(-116.66666666666667%, 0px, 0px)

sliderContent.css({
    '-webkit-transform': translate3D,
    '-ms-transform': translate3D,
    'transform': translate3D,
});

This will show the following when inspecting the element

<div class="sliderContent" style="transform: translate3d(-116.667%, 0px, 0px);"></div>

Expected/desired result

<div class="sliderContent" style="-webkit-transform: translate3d(-116.66666666666667%, 0px, 0px);-ms-transform: translate3d(-116.66666666666667%, 0px, 0px);transform: translate3d(-116.66666666666667%, 0px, 0px)"></div>

I've tried different ways of applying the style, with jQuery and plain JS, trying to cast or add toFixed(n), but it will still end up with 3 decimals and only showing the transform without the -webkit or -moz variants.

My priority is to keep percentage precision.

Edit

Regarding -webkit / -ms styles according to jQuery docs:

As of jQuery 1.8, the .css() setter will automatically take care of prefixing the property name.For example, take .css( "user-select", "none" ) in Chrome/Safari will set it as -webkit-user-select, Firefox will use -moz-user-select, and IE10 will use -ms-user-select.

about 4 years ago · Juan Pablo Isaza
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!