我想在切换按钮时更改变量的值。基于此,我想通过 CSS 切换图标的旋转
// this is the variable I want to change
var flag;
$(".outer_rotate_aero").click(function() {
$(".outer_rotate_aero_fa1").toggleClass("down");
flag = false;
$(".rotate_aero1").click(function() {
flag = true;
$(".fa2").toggleClass("down");
});
// I want to toggle a class containing a icon (ie rotate)
if (flag == true) {
$(".fa2").toggleClass("down");
}
});
最佳答案
var rotate = true;
$("div").html("rotate(0)")
$("div").click(function(){
rotate? $(this).html("rotate(180deg)"):$(this).html("rotate(0)")
$(this).toggleClass("down");
rotate=!rotate
})
div{
position:absolute;
left:50%;
top:50%;
background-color:red;
width:100px;
height:100px;
transition: transform 1s;
transform:translate(-50% , -50%);
}
div.down{
transform: translate(-50% , -50%) rotate(180deg)
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div></div>
可能是这样的!
关于javascript - 在切换按钮单击时更改变量的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56560392/