I want to get transform value with Jquery/Js, as below, translate(22, 6) scale(1) I want to get 22 6 and 1.
Asked
Active
Viewed 3,405 times
1 Answers
1
Try This:
$(document).ready(function(){
var res = '';
var str = $('.test').css('transform');
var x = str.split(',');
var len = x.length;
res += parseInt(x[len-2]) + " " + parseInt(x[len-1]) + " " + parseInt(x[len-3]);
alert(res);
})
.test {
transform:translate(22px,6px) scale(1) ;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="test"> my text</div>

Ehsan
- 12,655
- 3
- 25
- 44
-
thanks,but there is no 'px' in my string, it comes a 'NAN' by using your code. – Randy Ooorton Aug 22 '17 at 05:22
-
translate values must have px. – Ehsan Aug 22 '17 at 05:34
-
Thanks again,I'll mark it,I get this transform by $('div').attr('transform'),and it has no 'px' unit,so could you help me to solve it in this situation. – Randy Ooorton Aug 22 '17 at 05:42