我是全新的jQuery和有一些使用原型的经验。在Prototype中,有一个方法来“闪现”一个元素。简单地用另一种颜色突出它,然后让它变回正常,这样用户的眼睛就会被吸引到它上面。jQuery中有这样的方法吗?我看到淡出,淡出,和动画,但我没有看到任何像“闪光”。也许这三个中的一个可以与适当的输入一起使用?


当前回答

直接jquery,没有插件。它会闪烁指定的次数,在闪烁时改变背景颜色,然后再将其改变回来。

function blink(target, count, blinkspeed, bc) {
    let promises=[];
    const b=target.css(`background-color`);
    target.css(`background-color`, bc||b);
    for (i=1; i<count; i++) {
            const blink = target.fadeTo(blinkspeed||100, .3).fadeTo(blinkspeed||100, 1.0);
            promises.push(blink);
    }
    // wait for all the blinking to finish before changing the background color back
    $.when.apply(null, promises).done(function() {
            target.css(`background-color`, b);
    });
    promises=undefined;
}

例子:

blink($(`.alert-danger`), 5, 200, `yellow`);

其他回答

直接jquery,没有插件。它会闪烁指定的次数,在闪烁时改变背景颜色,然后再将其改变回来。

function blink(target, count, blinkspeed, bc) {
    let promises=[];
    const b=target.css(`background-color`);
    target.css(`background-color`, bc||b);
    for (i=1; i<count; i++) {
            const blink = target.fadeTo(blinkspeed||100, .3).fadeTo(blinkspeed||100, 1.0);
            promises.push(blink);
    }
    // wait for all the blinking to finish before changing the background color back
    $.when.apply(null, promises).done(function() {
            target.css(`background-color`, b);
    });
    promises=undefined;
}

例子:

blink($(`.alert-danger`), 5, 200, `yellow`);

下面的代码对我有用。定义两个渐入渐出函数,并将它们放在彼此的回调函数中。

var fIn = function() { $(this).fadeIn(300, fOut); };
var fOut = function() { $(this).fadeOut(300, fIn); };
$('#element').fadeOut(300, fIn);

以下控件控制闪光次数:

var count = 3;
var fIn = function() { $(this).fadeIn(300, fOut); };
var fOut = function() { if (--count > 0) $(this).fadeOut(300, fIn); };
$('#element').fadeOut(300, fIn);

我想,你可以使用jQuery UI中的高亮效果来实现同样的效果。

你可以使用jquery的pulse插件来强制将注意力集中在任何html元素上,控制速度、重复和颜色。

jquery . pulse() *带有演示

样本初始化:

$ (" .pulse4 ") .pulsate({速度:2500}) $("。CommandBox按钮:可见”)。脉动({颜色:“#f00”,速度:200,达到:85,重复:15})

创建两个类,给每个类一个背景色:

.flash{
 background: yellow;
}

.noflash{
 background: white;
}

用下面的类创建一个div:

<div class="noflash"></div>

下面的函数将切换类并使其显示为闪烁:

var i = 0, howManyTimes = 7;
function flashingDiv() {
    $('.flash').toggleClass("noFlash")
    i++;
    if( i <= howManyTimes ){
        setTimeout( f, 200 );
    }
}
f();