添加文本时淡出div背景

时间:2013-06-24 13:59:45

标签: javascript jquery html fadein fadeout

function showText(text) {
    $("#messages").append(text + "</br>");
    $("#messages").scrollTop($("#messages")[0].scrollHeight); 
    //line above is to automatically scroll the div to last added text
}

我想要添加的线条的背景,淡入然后淡出(它应该在半秒后淡出或类似的东西,只是为了引起用户的注意)。 我不知道如何使用CSS。如果可能的话,淡入淡出的颜色应该像灯泡黄色一样,就像突出显示一样:P 在此先感谢:)

1 个答案:

答案 0 :(得分:1)

我找到了您正在寻找的确切内容:

http://jsfiddle.net/BradleyStaples/G2tqd/

$.fn.bgColorFade = function(userOptions) {
// starting color, ending color, duration in ms
var options = $.extend({
    start: "yellow",
    end: "#fff",
    time: 500
}, userOptions || {});
$(this).css({
    backgroundColor: options.start
}).animate({
    backgroundColor: options.end
}, options.time);
return this;
};

$(".test").bgColorFade({
  time: 500
});

然后将其反转以使其淡出。

相关问题