图片正在旋转,但未分配变量$points
的值!
我想要的是当用户点击它旋转的图像然后它发出警报时。
请回答,我坚持下去。
var $toggle = 0;
var $points = 0;
$('.one').click(function () {
if ($toggle == 0) {
$(this).css("transform", "rotate(90deg)");
$points = 100;
$toggle = 1;
}
else if ($toggle == 1) {
$(this).css("transform", "rotate(180deg)");
$toggle = 2;
$points = 0;
}
else if ($toggle == 2) {
$toggle = 3;
$points = 0;
$(this).css("transform", "rotate(270deg)");
}
else if ($toggle == 3) {
$toggle = 0;
$(this).css("transform", "rotate(360deg)");
$points = 0;
}
else {
}
});
if ($points >= 100) {
alert("next mission");
}
else {
//nothing
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<img src="Assets/pipe.png" class="c1 one">
答案 0 :(得分:0)
将if($ points&gt; = 100)条件代码放在$(“。one”)中。点击事件。
var $toggle = 0;
var $points = 0;
$('.one').click(function () {
if ($toggle == 0) {
$(this).css("transform", "rotate(90deg)");
$points = 100;
$toggle = 1;
}
else if ($toggle == 1) {
$(this).css("transform", "rotate(180deg)");
$toggle = 2;
$points = 0;
}
else if ($toggle == 2) {
$toggle = 3;
$points = 0;
$(this).css("transform", "rotate(270deg)");
}
else if ($toggle == 3) {
$toggle = 0;
$(this).css("transform", "rotate(360deg)");
$points = 0;
}
else {
}
// put it inside this click event
if ($points >= 100) {
alert("next mission");
}
else {
//nothing
}
});
答案 1 :(得分:0)
将if条件置于click事件中,如下所示:
var $toggle = 0;
var $points = 0;
$('.one').click(function () {
alert($points);
if ($toggle == 0) {
$(this).css("transform", "rotate(90deg)");
$points = 100;
$toggle = 1;
}
else if ($toggle == 1) {
$(this).css("transform", "rotate(180deg)");
$toggle = 2;
$points = 0;
}
else if ($toggle == 2) {
$toggle = 3;
$points = 0;
$(this).css("transform", "rotate(270deg)");
}
else if ($toggle == 3) {
$toggle = 0;
$(this).css("transform", "rotate(360deg)");
$points = 0;
}
else {
}
if ($points >= 100) {
alert("next mission");
}
else {
//nothing
}
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<img src="Assets/pipe.png" class="c1 one">
&#13;