使用带有淡化元素的div块消失,并在设定的时间后重新出现

时间:2022-09-20 12:22:44

I'm trying to make a div disappear and reappear after a set amount of time.

我试图使div消失并在一段时间后重新出现。

Inside the div are div elements that fade in and fade out.

div内部是div元素,淡入淡出。

I thought this would work:

我认为这会奏效:

setTimeout(function() {
$( "#productDiv" ).removeAttr( "style" ).show().fadeIn();
}, 1000 );

but it isn't so I'm pretty sure I'm doing it wrong. I also can't figure out how to show the div again after a set time.

但事实并非如此,我很确定我做错了。我也无法弄清楚如何在一段时间后再次显示div。

Can anyone take a look at this and give me pointers?

任何人都可以看看这个并给我指点吗?

http://jsfiddle.net/linuxbastard/nGCNJ/5/

Thanks in advance.

提前致谢。

2 个解决方案

#1


1  

You can try this :- this will chain the effect after every 2secs

你可以试试这个: - 这将在每2秒之后链接效果

 $(document).ready(function(){
    setInterval(function() {
        $("#productDiv").show().delay(1000).fadeOut();
    }, 2000 );
 });

#2


0  

Do it like this :

像这样做 :

$("#productDiv").hide().delay(1000).fadeIn();

This hides the div, and program the fadeIn effect to be applied 1000 ms after that. That's the natural and idiomatic way to chain jquery effects.

这会隐藏div,并将fadeIn效果编程为在此之后1000 ms应用。这是链接jquery效果的自然和惯用方法。

#1


1  

You can try this :- this will chain the effect after every 2secs

你可以试试这个: - 这将在每2秒之后链接效果

 $(document).ready(function(){
    setInterval(function() {
        $("#productDiv").show().delay(1000).fadeOut();
    }, 2000 );
 });

#2


0  

Do it like this :

像这样做 :

$("#productDiv").hide().delay(1000).fadeIn();

This hides the div, and program the fadeIn effect to be applied 1000 ms after that. That's the natural and idiomatic way to chain jquery effects.

这会隐藏div,并将fadeIn效果编程为在此之后1000 ms应用。这是链接jquery效果的自然和惯用方法。