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


当前回答

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

其他回答

我正在用这个。虽然尚未在所有浏览器上测试。 按照你喜欢的方式修改它,

用法:hlight ($ (" # mydiv "));

function hlight(elementid){
    var hlight= "#fe1414"; //set the hightlight color
    var aspeed= 2000; //set animation speed
    var orig= "#ffffff"; // set default background color
    elementid.stop().css("background-color", hlight).animate({backgroundColor: orig}, aspeed);
}

注意:你需要一个jquery UI添加到你的头。

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

jquery . pulse() *带有演示

样本初始化:

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

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

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

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

我正在寻找这个问题的解决方案,但不依赖jQuery UI。

这就是我想出的,它为我工作(没有插件,只是Javascript和jQuery); -这是工作小提琴- http://jsfiddle.net/CriddleCraddle/yYcaY/2/

在你的CSS文件中设置当前的CSS参数为普通的CSS,并创建一个新类,只处理参数的变化,即background-color,并将其设置为'!“重要”来覆盖默认行为。像这样…

.button_flash {
background-color: #8DABFF !important;
}//This is the color to change to.  

然后只需使用下面的函数并将DOM元素作为一个字符串传递,一个表示您希望flash发生次数的整数,一个表示您希望更改到的类的整数,以及一个表示延迟的整数。

注意:如果你为'times'变量传递一个偶数,你将得到你开始时的类,如果你传递一个奇数,你将得到被切换的类。两者都有不同的用途。我用“I”来改变延迟时间,否则它们会同时发射,效果就会丢失。

function flashIt(element, times, klass, delay){
  for (var i=0; i < times; i++){
    setTimeout(function(){
      $(element).toggleClass(klass);
    }, delay + (300 * i));
  };
};

//Then run the following code with either another delay to delay the original start, or
// without another delay.  I have provided both options below.

//without a start delay just call
flashIt('.info_status button', 10, 'button_flash', 500)

//with a start delay just call
setTimeout(function(){
  flashIt('.info_status button', 10, 'button_flash', 500)
}, 4700);
// Just change the 4700 above to your liking for the start delay.  In this case, 
//I need about five seconds before the flash started.  

这是足够通用的,你可以编写任何你想要动画的代码。您甚至可以将延迟从300ms减少到33ms,并退色等。

// Flash linked to hash.
var hash = location.hash.substr(1);
if (hash) {
    hash = $("#" + hash);
    var color = hash.css("color"), count = 1;
    function hashFade () {
        if (++count < 7) setTimeout(hashFade, 300);
        hash.css("color", count % 2 ? color : "red");
    }
    hashFade();
}