HTML所有浏览器的闪烁文本,但位于正文的不同区域
HTML Blinking text for all browser but in different areas of the body
我正在尝试让html页面的不同区域闪烁"特定"文本。然而,我的代码使所有文本闪烁。这是我的代码:
<script type="text/javascript">
function blinker()
{
if(document.getElementById("blink"))
{
var d = document.getElementById("blink") ;
d.style.color= (d.style.color=='red'?'white':'red');
setTimeout('blinker()', 500);
}
}
</script>
<body bgcolor="#F0F0c0"; onload="blinker();">
<align="Right"><font size="3">Type of Alarm: <span style="font-
weight:bold"; div id="blink">Fire</div>
<align="Right"><font size="3"># of Employees Clocked In:<span style="font-
weight:bold"; div Id="blink">5</div>
我只想让"火"answers"5"这两个字闪烁,但一切都在闪烁。
我只是尽可能地表达你可能想要实现的目标,这实际上仍然没有达到预期的行为,但根据你提供的片段,你可能会同意我的观点,这并不容易。
我将给你一个示例plunkr,你可以编辑它来帮助你:Plunkr
function blinker()
{
if(document.getElementById("blink"))
{
var d = document.getElementById("blink") ;
d.style.color= (d.style.color =='red' ? 'white' : 'red');
setTimeout(blinker(), 500);
}
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body bgcolor="#F0F0c0" onload="blinker()">
<span style="font-weight:bold; font-size:30px;">Type of Alarm:</span>
<div id="blink">Fire</div>
<span style="font-weight:bold; font-size:30px;"># of Employees Clocked In:</span>
<div id="blink">5</div>
</body>
</html>
标记中有几个问题需要解决。如果你要重新开始,你可以通过CSS动画来实现你想要做的事情。
您定义了0%和100%的关键帧颜色,然后任何具有blink
类的元素都将在这些颜色之间切换,如下所示:
/* -- CSS -- */
@keyframes colours {
0% {color: #f00;}
100% {color: #fff;}
}
.blink { /*browser prefixes removed for brevity*/
animation-direction: normal;
animation-duration: 1s;
animation-iteration-count: infinite;
animation-name: colours;
animation-timing-function: ease;
}
<!-- HTML -->
Type of Alarm:<span class="blink">Fire</span><br />
# of Employees Clocked In:<span class="blink">5</span>
您的html代码无效。
你为什么不使用这个标签:
<blink>
您可以从这个例子开始,因为我们知道您要做什么,但您有无效的标记:
https://jsfiddle.net/jws5wpfm/
HTML
<h3>Type of Alarm:
<span class="blink white">Fire</span>
<br/>
# of Employees Clocked In
<span class="blink">5</span>
</h3>
CSS
.blink {
color:red
}
.white {
color: white !important
}
JS
window.setInterval(function() {
$("span").toggleClass("white");
}, 500);
相关文章:
- javascript问题正文样式
- JQuery在单击正文时隐藏上下文菜单
- 我可以在网页正文中插入文本链接吗
- 未捕获的类型错误:无法设置属性'innerHTML'如果为null,则将脚本移动到正文不会;不起作用
- 正在尝试将标题标记添加到mailto链接,正文中包含URL
- 在外部(正文)单击时关闭弹出窗口
- 正文中未显示内容
- 将电子邮件正文导出到Google Sheets中的多个单元格中
- 如何从应用于正文的css中排除特定的表单
- 使用 postman.setNextRequest() 在发送之前填充请求正文
- 阻止在单击和关闭覆盖菜单css时滚动正文
- 如何在不支持HTML字符的邮件正文中发送%签名
- 检测垂直滚动和滚动条宽度,并将宽度更改应用于正文
- 如何设置正文相对于屏幕大小的字体大小
- 粘性标头 - 相对于动态标头长度的正文位置
- 如果我将高度应用于正文,页面将滚动到顶部
- 如何在页面中捕获“正文”和“正文”事件[Jquery].
- 专注于加载时 iframe 中的内容可编辑正文
- 如何使文档(页面)向左和顶部以及相对于正文的滚动(向左和顶部滚动)
- 在 xhtml 中为正文元素设置背景图像(适用于不同的显示器和分辨率)