2012-05-24 59 views

回答

1

您可以使用switchClass,像:

$("#element").switchClass("removeThisClass", "addThisClass", 1000) 

演示小提琴:HERE

参考:JQuery Docs

+0

尝试http://jsfiddle.net/RW2s4/7/不工作 – Rosh

+0

请尝试在这里http://jsfiddle.net/RW2s4/11/你没有把滴答声放在左侧的JQuery UI框中(在下面jQuery下拉)。你需要这个。此外,由于某些原因,标记中的单击事件在jsfiddle中不起作用。我已将它移入JavaScript中。试试 – mattytommo

+1

@mattytommo - 标记中的FYI onclick在jsfiddle中可以工作,但如果你的javascrip是'onDomLoad'或'onLoad',因为它们被封闭在窗口范围之外。如果你想要正常的事件(你几乎从不使用jQuery),选择'head(no wrap)'。所以修复这个jsfiddle就像滴答jQuery UI并更改下拉列表一样简单:http://jsfiddle.net/RW2s4/14/ – Jamiec

10

这个小脚本添加了类'高亮'两秒到输入栏:

$('#text').change(function() { 
    var jElement = $(this); 
    jElement.addClass('highlight'); 
    setTimeout(
     function() { jElement.removeClass('highlight'); }, 
     2000 
    ); 
}); 

另请参阅this example

here您和我的解决方案的组合。

+0

[这里](http://jsfiddle.net/RW2s4/15/)你和我的解决方案的组合(没有jQuery UI)。 – scessor

0

见其中一些间隔之后动画元素直播Demo

$(function(){ 

    setTimeout(ChangeBorder, 2000); 

    function ChangeBorder() { 
    $(".highlight").css({"border-color":"red"}); 
    } 
}); 
0

检查jQuery的动画功能:

演示:上单击幻灯片http://jsfiddle.net/umSkg/2/

$(document).ready(function(){ 
    var ogColor = $("#inpt").css("border-left-color"); 
    $("#trggr").click(function(){ 
     var inpt = $("#inpt"); 
     var delay = 1000; 
     inpt.animate({ borderColor: "#EAC117" }, delay,function(){ 
     //revert after completing 
     inpt.animate({ borderColor: ogColor }, delay); 
     }); 
    }); 

}); 
+1

你尝试过你的演示吗?它在FF12中无法恢复(在IE8中工作!) – Jamiec

+0

代码已更新 –

+0

奇怪的解决方法,border-left-color在FF中工作,但不是边框颜色。你是对的,虽然...现在的作品! – Jamiec

0

突出的div的div

$('.box').click(function() { 
    var jElement = $(this); 
    jElement.addClass('highlight'); 
    setTimeout(
     function() { jElement.removeClass('highlight'); }, 
     500 
    ); 
    //$(window).scrollTop($('.box3').offset().top,100); 
    $("html, body").delay(100).animate({ 
     scrollTop: $('.box2').offset().top 
    }, 2000); 

}); 


    <button>http://jsfiddle.net/tyPct/198/ </button> 
0

使用效果功能

$('#component').effect("highlight", {color: 'red'}, 2000);