Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get 'translateX' position in jQuery

Tags:

jquery

This code sets the translateX position:

 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 then?

like image 676
Faizan Avatar asked Feb 03 '14 08:02

Faizan


1 Answers

Try this,

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

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

Upadate:

Demo link jsfiddle

like image 148
dhana Avatar answered Oct 25 '22 19:10

dhana