【问题标题】:How to make button blinking infinite, but with possibility to stop at anytime如何使按钮闪烁无限,但可以随时停止
【发布时间】:2011-12-13 06:35:31
【问题描述】:

我需要让按钮在其他元素触发后开始闪烁,例如选中复选框 - 请参见下面的代码:

<label>I agree with the terms</label>
<input class="some_check" type="checkbox" id="Signed">
<button class="buttonstyle" name="buttonNext" onClick="nextChoose('NEXT')" disabled>Proceed!</button>

闪烁必须是无限的,直到:

  1. 用户点击按钮或
  2. 取消选中复选框。

我知道 jQuery UI 中有 .effect() 方法,但它是有时间限制的 如果我通过回调循环它,我怎样才能打破它以返回先前状态的按钮?

【问题讨论】:

  • 闪烁标签死掉是有原因的...
  • 你的意思是所有这些效果看起来很恶心?看看这里 - jqueryui.com/demos/effect,我认为他们很聪明

标签: jquery jquery-ui effects jquery-ui-button


【解决方案1】:

也许您正在寻找类似THIS FIDDLE 的东西

CSS:

#click, #btn {margin: 20px;}

JavaScript:

var timer;

$("#blink").on('change', function() {
    if ($("#blink").is(':checked')) {
        blinking($("#btn"));
    } else {
        clearInterval(timer);
    }
});

$("#btn").click(function() {
    clearInterval(timer);
    $("#blink").attr('checked', false);
});



function blinking(elm) {
    timer = setInterval(blink, 10);
    function blink() {
        elm.fadeOut(400, function() {
           elm.fadeIn(400);
        });
    }
}

HTML:

<input type="checkbox" id="blink"/>
<input type="button" value="CLICK ME" id="btn" />

【讨论】:

  • @shershen 我知道现在问这个可能为时已晚,但我被困在这里.. 我正在使用这个解决方案,一段时间后我收到“堆栈内存不足”的错误..你面临这个问题?..如果是,你使用了什么解决方案?
【解决方案2】:

您可以使用setInterval 使某些事情一遍又一遍地发生,然后在其返回值上调用clearInterval 以使其停止。 Here's a working example 让您开始。

【讨论】:

  • 也许我的解释不正确,但是在我选中复选框后按钮必须开始闪烁 - 这甚至不是重点,但重要的是,在取消选中后按钮必须返回之前的状态
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-29
相关资源
最近更新 更多