Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change "scale" attribute in CSS "transform"

I have the following div

<div style="transform-origin: left top 0px; transform: translate3d(0px, -26px, 0px) scale(1);">

As you can see, transform contains scale(1). What's the best way to change scale value?

Thank you for your help.

like image 420
Andi Pavllo Avatar asked Feb 21 '26 05:02

Andi Pavllo


1 Answers

Sure, using javascript. There are many ways to do it, I'd do it using a regex.

function changeScale(newScale){
    var div = document.getElementById('theID');
    var curTrans = div.style.transform;
    var newScaleString = 'scale(' + newScale + ')';
    var regex = /scale\([0-9|\.]*\)/;
    var newTrans = curTrans.replace(regex, newScaleString);
    div.style.transform = newTrans;
}

Or with less lines:

function changeScale(newScale){
    var div = document.getElementById('theID');
    div.style.transform = div.style.transform.replace(/scale\([0-9|\.]*\)/, 'scale(' + newScale + ')');
}
like image 136
kmaork Avatar answered Feb 22 '26 18:02

kmaork



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!