因此,我希望我的登录门户页面的标题后有一个闪烁的下划线。所有的超文本标记语言都很好,它在JavaScript中的样式改变之间得到了一种延迟。我尝试过这样做:
const underscore = document.getElementById('flashingUnderscore');
function flash() {
while (true) {
underscore.style.display = 'none';
window.setTimeout(dump,1000);
underscore.style.display = 'block';
window.setTimeout(dump,1000);
};
};
function dump() {
return;
}
但这显然是行不通的。因此,当我有点困惑的时候,我向社区寻求想法。Image of what I'm trying to achieve
发布于 2018-08-24 06:48:01
考虑使用setInterval
而不是setTimeout
,这样就可以避免循环。然后,您可以执行以下操作:
setInterval(function() {
underscore.style.display = underscore.style.display == 'none' ? 'block' : 'none';
}, 1000);
发布于 2018-08-24 06:47:44
对当前状态使用window.setInterval
和布尔值
const underscore = document.getElementById('flashingUnderscore');
var displayed = true;
function flash() {
if(displayed) {
underscore.style.display = 'none';
} else {
underscore.style.display = 'block';
}
displayed = !displayed;
}
window.setInterval(flash, 1000);
<div id="flashingUnderscore">_</div>
发布于 2018-08-24 06:49:28
简单
window.setInterval(function(){
var yourDiv = document.getElementById('flashingUnderscore');
if(yourDiv.style.visibility == "visible")
yourDiv.style.visibility == "hidden")
else
yourDiv.style.visibility == "visible")
}, 1000);
其他解决方案会更改显示值,但是,如果它占用空间,则可能会更改布局。可见性只会隐藏它。
https://stackoverflow.com/questions/51995233
复制相似问题