Get the 'translateX' position in jQuery

This code sets the position of translateX:

 var pos = -500px;
 $(.slide).css('-webkit-transform',  "translateX(" + pos+ "px)");

but the following code does not get the translateX position:

 var currTrans = $(".slide").css('-webkit-transform', "translateX()");

Why? What is the correct way to get the value?

+4
source share
1 answer

Try it,

var pos = -500;
 $('.slide').css('-webkit-transform',  'translateX(' + pos+ 'px)');

var currTrans = $('.slide').css('-webkit-transform').split(/[()]/)[1];
var posx = currTrans.split(',')[4];

Upadate:

Jsfiddle demo link

+8
source

Source: https://habr.com/ru/post/1525011/


All Articles