如何在html / javascript中制作文字? [英] How to make a text flash in html/javascript?
问题描述
我知道闪存文本在许多地方都被禁止,但仍然是我的客户端需要它,我需要使用HTML,JavaScript来闪现一行文本,这是可行的。我希望文本在几秒钟内出现并消失并继续此循环。
I know flashing text is banned at many places but still as my client requires it, I need to flash one line of text using HTML, JavaScript which ever is feasible. I would like the text to appear and disappear within seconds and continue this cycle.
我知道文本修饰:CSS中的blink可以做到这一点但它只适用于FireFox,歌剧。我需要在所有浏览器中使用Firefox,Chrome,Safari,IE。我搜索并尝试了很多Javascript代码,但似乎都没有。
I know text-decoration:blink in CSS can do this but it only works in FireFox, Opera. And I need this to work in all browsers Firefox, Chrome, Safari, IE. I have searched and tried a lot of Javascript codes but none seem to be working.
所以任何知道如何操作的人,请发布一个有效的代码版本会闪现所有浏览器中的文字。
So any one who knows how to do this, please post a working version of code which does flash the text in all browsers.
推荐答案
你可以这样做:
<div id="Foo">Blink</div>
使用以下脚本:
$(document).ready(function() {
var f = document.getElementById('Foo');
setInterval(function() {
f.style.display = (f.style.display == 'none' ? '' : 'none');
}, 1000);
});
示例: http://jsfiddle.net/7XRcJ/
如果您不使用jQuery,可以尝试这样的事情:
If you're not using jQuery, you can try something like this:
window.addEventListener("load", function() {
var f = document.getElementById('Foo');
setInterval(function() {
f.style.display = (f.style.display == 'none' ? '' : 'none');
}, 1000);
}, false);
各种浏览器都有不同的绑定事件处理程序的方法,所以我强烈建议使用某种交叉方式浏览器库如果可能的话。
Various browsers have different ways of binding event handlers, so I would strongly suggest using some sort of cross-browser library for this sort of thing if possible.
您也可以尝试在body标签中使用onload事件。这是我在FF和IE7中测试过的完整示例:
You can also try using the onload event in the body tag. Here's a full example that I've tested in FF and IE7:
function blink() {
var f = document.getElementById('Foo');
setInterval(function() {
f.style.display = (f.style.display == 'none' ? '' : 'none');
}, 1000);
}
<html>
<body onload="blink();">
<div id="Foo">Blink</div>
</body>
</html>
这篇关于如何在html / javascript中制作文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!