Javascript 如何制作<;p>;标记在X时间出现,在X时间消失
我试图让文本出现后1分钟的用户在网站上,并离开后2秒 我知道如何使它淡出:Javascript 如何制作<;p>;标记在X时间出现,在X时间消失,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我试图让文本出现后1分钟的用户在网站上,并离开后2秒 我知道如何使它淡出: setTimeout(fade_out, 2000); function fade_out() { $("#msg").fadeOut().empty(); } 但我需要帮助让它消失 我不太理解JS,所以请尝试包括一个例子 setTimeout( function() { $("£msg").fadeIn(200); //call the fade out function here }, 60000)
setTimeout(fade_out, 2000);
function fade_out() {
$("#msg").fadeOut().empty();
}
但我需要帮助让它消失
我不太理解JS,所以请尝试包括一个例子
setTimeout(
function()
{
$("£msg").fadeIn(200);
//call the fade out function here
}, 60000);
资料来源:
来源:除了您的代码之外,还可以使用
fadeIn()
和delay()
::
注意::在本演示中,我使用了一些短时间,您可以根据自己的需要进行调整
setTimeout(淡入淡出,2000年);
函数fade_in(){
$(“#msg”).fadeIn().delay(1000.fadeOut();
}
#msg{
显示:无;
填充:50px;
背景:红色;
颜色:白色;
}
警报
除了您的代码之外,请使用fadeIn()
和delay()
::
注意::在本演示中,我使用了一些短时间,您可以根据自己的需要进行调整
setTimeout(淡入淡出,2000年);
函数fade_in(){
$(“#msg”).fadeIn().delay(1000.fadeOut();
}
#msg{
显示:无;
填充:50px;
背景:红色;
颜色:白色;
}
警告
您已在正确的轨道上。只是需要在淡出之前淡出
//fade in in 6 seconds (change to 60000 for 1 minute)
setTimeout(fade_in, 6000);
//function to fade it in
function fade_in() {
$("p").fadeIn();
//in this function we can start to fade out after 2 seconds
setTimeout(fade_out, 2000);
}
//function to fade out
function fade_out() {
$("p").fadeOut();
}
例如:
您走在正确的轨道上。只是需要在淡出之前淡出
//fade in in 6 seconds (change to 60000 for 1 minute)
setTimeout(fade_in, 6000);
//function to fade it in
function fade_in() {
$("p").fadeIn();
//in this function we can start to fade out after 2 seconds
setTimeout(fade_out, 2000);
}
//function to fade out
function fade_out() {
$("p").fadeOut();
}
例如:
Jquery可能是最简单的答案,但您也可以使用纯Java语言,而无需任何javascript HTML:
<p id="element">P IS SHOWN</p>
#element {
padding: 50px;
background: red;
color: white;
}
#element {
-moz-animation: cssAnimation 64s ease-in;
/* Firefox */
-webkit-animation: cssAnimation 64s ease-in;
/* Safari and Chrome */
-o-animation: cssAnimation 64s ease-in;
/* Opera */
animation: cssAnimation 64s ease-in;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
@keyframes cssAnimation {
0% {opacity: 0;display:none;}
/* 59 sec : start fading in*/
92% {opacity: 0;display:block;}
/* 60 sec : visible */
94% {opacity: 1;display:block;}
/* 62 sec : start fading out */
97% {opacity: 1;display:block;}
/* 63 sec : not visible */
99% {opacity: 0;display:block;}
/* 64 sec */
100% {opacity: 0;display:none;}
}
这里有一个小问题(持续6秒):Jquery可能是最简单的答案,但您也可以使用纯语言,而不使用任何javascript HTML:
<p id="element">P IS SHOWN</p>
#element {
padding: 50px;
background: red;
color: white;
}
#element {
-moz-animation: cssAnimation 64s ease-in;
/* Firefox */
-webkit-animation: cssAnimation 64s ease-in;
/* Safari and Chrome */
-o-animation: cssAnimation 64s ease-in;
/* Opera */
animation: cssAnimation 64s ease-in;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
@keyframes cssAnimation {
0% {opacity: 0;display:none;}
/* 59 sec : start fading in*/
92% {opacity: 0;display:block;}
/* 60 sec : visible */
94% {opacity: 1;display:block;}
/* 62 sec : start fading out */
97% {opacity: 1;display:block;}
/* 63 sec : not visible */
99% {opacity: 0;display:block;}
/* 64 sec */
100% {opacity: 0;display:none;}
}
这里有一把小提琴(持续6秒):要在60秒后淡入文本,然后在2秒后淡出文本,您可以执行以下操作:
var fadeOutText = function () {
$("#msg").fadeOut(); // select the message and fade it out
};
var fadeInText = function () {
$("#msg").fadeIn(); // select the message and fade it in
setTimeout(fadeOutText, 2000); // set the text to fade out in another 2 seconds (2000 ms)
};
setTimeout(fadeInText, 60000); // start the fade in after 60 seconds (60000 ms)
要在60秒后淡入文本,然后在2秒后淡出文本,可以执行以下操作:
var fadeOutText = function () {
$("#msg").fadeOut(); // select the message and fade it out
};
var fadeInText = function () {
$("#msg").fadeIn(); // select the message and fade it in
setTimeout(fadeOutText, 2000); // set the text to fade out in another 2 seconds (2000 ms)
};
setTimeout(fadeInText, 60000); // start the fade in after 60 seconds (60000 ms)
只需使用
fadeIn()
…打开jQuery API并查找fade
方法…不难只需使用fadeIn()
…打开jQuery API并查找fade
方法…不难。请详细说明您的答案,再添加一点关于您提供的解决方案的说明?请详细说明您的答案,再添加一点关于您提供的解决方案的说明,好吗?