2

I want to get transform value with Jquery/Js, as below, translate(22, 6) scale(1) I want to get 22 6 and 1.

0

1 Answer 1

2

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>

Sign up to request clarification or add additional context in comments.

3 Comments

thanks,but there is no 'px' in my string, it comes a 'NAN' by using your code.
translate values must have px.
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.