简单的JavaScript动画1秒钟以突出显示文本? [英] Simple JavaScript Animation for 1 Second to Highlight Text?

查看:92
本文介绍了简单的JavaScript动画1秒钟以突出显示文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过谷歌搜索但我发现很多我无法概述这一切,所以我需要你的经验:

I searched by google but I found that much I can't overview it all, so I need your experience:

我需要突出显示文字1秒。例如,一个简单的眨眼 - 用颜色或类似的效果。

I need to highlight a text for 1 second. For example a simple "blink"-effect with a color or something like that.

我已经尝试过JQuery-Animation,但是对于较新版本的Firefox / Internet Explorer来说,它似乎非常麻烦。

I tried JQuery-Animation allready but it seems very bugged with newer versions of Firefox / Internet Explorer.

你有什么想法吗?

推荐答案

function highlightFor(id,color,seconds){
    var element = document.getElementById(id)
    var origcolor = element.style.backgroundColor
    element.style.backgroundColor = color;
    var t = setTimeout(function(){
       element.style.backgroundColor = origcolor;
    },(seconds*1000));
}

应该有效。为它提供元素的id,高亮颜色以及要显示高亮显示的时间(以秒为单位)。例如

should work. Supply it with the id of the element, the highlight color and the time you want the highlight to display for (in seconds). For example

highlightFor('object','yellow',3);

编辑:就样式表中设置的颜色而言,我强烈建议使用javascript库(如jQuery的)。我知道你说你遇到了一些问题,但很可能你写的代码中有一个小错误就是给你这个意见。如果您对jQuery有任何疑问,请询问!

As far as colours set in stylesheets is concerned, I strongly suggest using a javascript library (like jQuery). I know you say that you've had some problems with it, but it's most likely there's a tiny bug in the code you've written that's giving you that opinion. Just ask on SO if you have any questions about jQuery!

这篇关于简单的JavaScript动画1秒钟以突出显示文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆