14

Currently I have a class with transform value rotate(57deg), when alert

$(".div-1").css("transform") it is giving matrix value.

<style> 
 .div-1{
     transform: rotate(57deg);
     }                 
</style>   
<div class="div-1">Test</div>

I need to add scale(-1, 1) to the existing transform value using Jquery

. so .div-1 transform value become div-1 { transform: scale(-1, 1) rotate(57deg); } How to do this ? Here 57 is just a number , it will change always. so what I need is add scale( -1 , 1) to the current transform value . Please help .

6
  • 1
    Create a class with the scale in it and then just dynamically add the class to the div: stackoverflow.com/questions/35429935/… Commented Dec 28, 2016 at 6:05
  • 2
    $(".div-1").css("transform","scale(-1,1) rotate("+yourDeg+"deg)"); is not working? Commented Dec 28, 2016 at 6:06
  • should 57 be a variable? Commented Dec 28, 2016 at 6:35
  • 57 is variable. consider it as a n degree. Commented Dec 28, 2016 at 6:37
  • Try the comment given by @AntalGyuri, it should work. Commented Dec 28, 2016 at 9:00

3 Answers 3

6

you can do something like this :

var css = $('.div-1').css("transform");
css = css+" scale(-1,1)";
$('.div-1').css('transform',css);
Sign up to request clarification or add additional context in comments.

1 Comment

Yes this is working . I never thought it is this much simple . When seeing matrix value , i didn't try any thing & i just asked without trying . Thank you friend .
1
<style>
    div {
        -ms-transform: rotate(57deg); // IE 9  
        -webkit-transform: rotate(57deg); // Chrome, Safari, Opera  
        transform: rotate(57deg);
    }
</style>

Comments

-1

ALternate solution is to create two classes as

<style> 
 .div-1{
     transform: rotate(57deg);
     }    
  .div-2{
     transform: scale(-1, 1) rotate(57deg);
     }             
</style>   
<div class="div-1">Test</div>

then in jquery do the following :

if(condition == true){
$(".div-1").addClass("div-1");
$(".div-1").removeClass("div-2");
} else {
$(".div-1").addClass("div-2");
$(".div-1").removeClass("div-1");
}

2 Comments

This is not correct answer friend . Because here one time either i get scale effect or i get rotate effect . But i need both at a time as i explained .div-1 { transform: scale(-1, 1) rotate(57deg); }
once the class div-2 will be applies you will get both effect , what is the issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.