javascript - jQuery .fadeOut then wait, then .fadeIn doesn't work - Stack Overflow

I'm trying to fade out a div, then fade in another div, and that works for me, the problem is I�

I'm trying to fade out a div, then fade in another div, and that works for me, the problem is I'm not able to delay it, so first div doesn't push the other div down...

This is my HTML (everything is inline):

<!doctype html>
<html>
    <head>
        <title>JavaScript popup</title>
        <meta charset="utf-8">
        <script src=".12.0/jquery.min.js"></script>
        <script src="main.js" type="text/javascript"></script>
    </head>
    <script type="text/javascript">
        $(document).ready(function(){
            $(".main").hide();
        });
        $("#continue-button").click(function(){
            $(".vge-eksponering").hide();
            $(".main").show();      
        });        
    </script>
    
    <body style="background-color:lightgrey;">
        <div class="vge-eksponering" style="text-align:center;">
            <h1>Tjek VGEs hjemmeside ud på:
            <br>
            <a href="" target="_blank">www.vge.dk</a></h1>
            <button id="continue-button" style="font-size:2em;">Fortsæt til VGE News</button>
        </div>
        <script>
            $("#continue-button").click(function(){
                $(".vge-eksponering").fadeOut(1200);
                $(".main").fadeIn(1200);
            });  
        </script>
        <div class="main" style="background-color:lightblue;">
            <h1>JavaScript popup</h1>
            <p>Hopefully this will work soon...</p>
        </div>
    </body>
</html>

I'm trying to fade out a div, then fade in another div, and that works for me, the problem is I'm not able to delay it, so first div doesn't push the other div down...

This is my HTML (everything is inline):

<!doctype html>
<html>
    <head>
        <title>JavaScript popup</title>
        <meta charset="utf-8">
        <script src="https://ajax.googleapis./ajax/libs/jquery/1.12.0/jquery.min.js"></script>
        <script src="main.js" type="text/javascript"></script>
    </head>
    <script type="text/javascript">
        $(document).ready(function(){
            $(".main").hide();
        });
        $("#continue-button").click(function(){
            $(".vge-eksponering").hide();
            $(".main").show();      
        });        
    </script>
    
    <body style="background-color:lightgrey;">
        <div class="vge-eksponering" style="text-align:center;">
            <h1>Tjek VGEs hjemmeside ud på:
            <br>
            <a href="http://www.vge.dk" target="_blank">www.vge.dk</a></h1>
            <button id="continue-button" style="font-size:2em;">Fortsæt til VGE News</button>
        </div>
        <script>
            $("#continue-button").click(function(){
                $(".vge-eksponering").fadeOut(1200);
                $(".main").fadeIn(1200);
            });  
        </script>
        <div class="main" style="background-color:lightblue;">
            <h1>JavaScript popup</h1>
            <p>Hopefully this will work soon...</p>
        </div>
    </body>
</html>

EDIT: I used this, and it worked.

$(".vge-eksponering").fadeOut(1200);
$(".main").delay(1200).fadeIn(1200);
Share Improve this question edited Feb 4, 2016 at 20:24 Kevin From asked Feb 4, 2016 at 18:16 Kevin FromKevin From 1522 silver badges10 bronze badges 1
  • You want to fade out .vge-eksponering and, when it's done fading out, fade in .main? – T.J. Crowder Commented Feb 4, 2016 at 18:19
Add a ment  | 

2 Answers 2

Reset to default 6

You have (at least) two choices:

If there's only one .vge-eksponering element, then use the pletion callback fadeOut gives you:

$(".vge-eksponering").fadeOut(1200, function() {
    $(".main").fadeIn(1200);
});

Or just use delay with a value equivalent to the first fadeOut:

$(".vge-eksponering").fadeOut(1200);
$(".main").delay(1200).fadeIn(1200);

use setInterval

setInterval(function() {
  $(".main").fadeIn(1200);
}, 1200);

a tutorial on setInterval http://www.w3schools./jsref/met_win_setinterval.asp

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745653206a4638387.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信