[英]Javascript minimize and maximize
I want to scale the div onclick to 25% and back onclick to 50%. 我想将div onclick缩放到25%,然后再将onclick缩放到50%。 Why isn't it scaling back to 50%?
为什么不缩小到50%?
var minimize = document.getElementById('minimize');
var container = document.getElementById('container');
minimize.onclick = function(){
if(container.style.width = "50%") {
container.style.width = "25%";
container.style.height = "25%";
}else{
container.style.width = "50%";
container.style.height = "50%";
}
console.log(container.style.width);
}
} }
There's an assignment rather than a comparison in your if statement: if语句中有一个赋值而不是一个比较:
if (container.style.width = "50%") {
Should be: 应该:
if (container.style.width == "50%") {
The assignment will return the assigned value - "50%". 分配将返回分配的值-“ 50%”。 That value is truthy, so the code inside the if statement will be executed.
该值是真实的,因此将执行if语句中的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.