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


当前回答

我真不敢相信这还不是这个问题。你要做的就是:

("#someElement").show('highlight',{color: '#C8FB5E'},'fast');

这完全是你想要它做的,超级简单,适用于show()和hide()方法。

其他回答

$('#district').css({opacity: 0});
$('#district').animate({opacity: 1}, 700 );

你可以进一步扩展Desheng Li的方法,允许迭代计数进行多次闪光,如下所示:

// Extend jquery with flashing for elements
$.fn.flash = function(duration, iterations) {
    duration = duration || 1000; // Default to 1 second
    iterations = iterations || 1; // Default to 1 iteration
    var iterationDuration = Math.floor(duration / iterations);

    for (var i = 0; i < iterations; i++) {
        this.fadeOut(iterationDuration).fadeIn(iterationDuration);
    }
    return this;
}

然后你可以调用方法的时间和闪光的数量:

$("#someElementId").flash(1000, 4); // Flash 4 times over a period of 1 second

直接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`);

我真不敢相信这还不是这个问题。你要做的就是:

("#someElement").show('highlight',{color: '#C8FB5E'},'fast');

这完全是你想要它做的,超级简单,适用于show()和hide()方法。

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

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);