简体   繁体   English

停止jquery淡入淡出效果?

[英]Stop jquery fading effect?

I am trying to make a blinking light recording effect.我正在尝试制作闪烁的灯光录制效果。 Here is the code I have so far:这是我到目前为止的代码:

 $("#stop").hide(); function blink() { $("#red").fadeOut(500); $("#red").fadeIn(500); } $("#start").click(function () { $("#start").hide(); $("#stop").show(); window.test = setInterval(blink, 500); }); $("#stop").click(function () { window.clearInterval(test); $("#stop").hide(); $("#start").show(); });
 <button class="success" id="start">Start</button> <button id="stop">Stop</button>

Here is the blinking light image:这是闪烁的灯光图像:

 <img src="record.png" id="red" />
The image is solid and the jquery fades it in and out. 图像是实心的,jQuery 将其淡入淡出。 But when you click the stop button it does not stop; 但是当您单击停止按钮时,它不会停止; it keeps blinking; 它一直闪烁; I also tried to use jquery: .stop(); 我也尝试使用 jquery: .stop(); . . But it did not work. 但它没有用。 How can I fix this? 我怎样才能解决这个问题? Thanks for all your help in advance! 提前感谢您的所有帮助!

Try:尝试:

function blink() {
  $("#red").fadeOut(500);
  $("#red").fadeIn(500);
}

$("#start").click(function () {
  $("#start").hide();
  $("#stop").show();

  window.test = setInterval(blink, 500);
});

$("#stop").click(function () {
  window.clearInterval(test);
  $("#stop").stop();
  $("#start").show();
});

It should stop the light after the current interval.它应该在当前间隔后停止灯光。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM