gpt4 book ai didi

javascript - 延迟隐藏元素

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:14:14 25 4
gpt4 key购买 nike

在这种情况下,元素隐藏在一个位置。不明白为什么它一开始不显示“P”标签然后慢慢隐藏它。请帮我解决一个问题。

var step = 0.1;
var delay = 90000;
var displayMe = function() {
if (element.style.opacity < 1) {
element.style.opacity += step;
setTimeout('displayMe()', delay);
}
}

var hideMe = function() {
var elem = document.getElementById('regform');
if (elem.style.opacity >= 0) {
elem.style.opacity -= step;
setTimeout('hideMe ()', delay);
}
}

hideMe();
<p id="regform">aaaaaaaaaaaaaaaaa</p>

最佳答案

Element.style.prop将只读取内联样式。定义 style='opacity:1'对于 <p>元素。

var step = 0.1;
var delay = 1000;

var displayMe = function() {
if (element.style.opacity < 1) {
element.style.opacity += step;
setTimeout(displayMe, delay);
}
}

var hideMe = function() {
var elem = document.getElementById('regform');
if (elem.style.opacity >= 0) {
elem.style.opacity -= step;
setTimeout(hideMe, delay);
}
}

hideMe();
<p id="regform" style='opacity:1'>aaaaaaaaaaaaaaaaa</p>

关于javascript - 延迟隐藏元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36442254/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com