Issue
Please tell me why I can’t set the scale for the div?
var a = 0.1;
var b = 0.1;
var scale = a+b;
$(".item").css('scale', scale)
.item {
width: 100px;
height: 100px;
background: blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="item"></div>
Solution
As per the documentation :
When a number is passed as the value, jQuery will convert it to a string and add px to the end of that string. If the property requires units other than px, convert the value to a string and add the appropriate units before calling the method.
Thus, the parameter has to be a string, not a number :
var a = 0.1;
var b = 0.1;
var scale = a+b;
$(".item").css('scale', scale.toString())
.item {
width: 100px;
height: 100px;
background: blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="item"></div>
Answered By - Tom
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.