JavaScript how to show two div one by one repeatedly powerpoint slide show repeated

i am working on developing on an Html page where i have two div. In each div i have one image. I want that each image should be visible for 2 second and after that the second div should get visible. This function should get repeatedly. For this i used following code.

<script type="text/javascript">
 $( document ).ready(function() {
     $(".logo-outer").show();
     setTimeout(function () {
         $(".logo-outer").hide();
         $(".logo-outernew").hide();
     }, 2000);
 });
 </script>

But the above code is not working and image in not visible or invisible.

Answer:1

you can make use of SetInterval function instead of timeout function

below is example code , it might now working please check proper function . main point is make use of interval function

var myInterval = setInterval(function () {
      if($(".logo-outer").is(':visible'))
       {
             $(".logo-outer").hide();
             $(".logo-outernew").show();
       }
       else
       {
             $(".logo-outer").show();
             $(".logo-outernew").hide();
       }
        },2000); 

if you want to stop clearInterval(myInterval);

Answer:2
 setInterval(function () {
     if ($(".logo-outer").css("display") == "none"){
        $(".logo-outer").show();
     }
     else{
        $(".logo-outer").hide();
     }
 }, 2000);

Every 2seconds it runs the functions and if logo outer is not visible it will show it, else if it's visible it will hide it.

Answer:3

I believe that you have also made an error in hiding the second image insted of displaying it (inside setTimeout):

     $(".logo-outer").hide();
     $(".logo-outernew").hide();

I believe the second one should be $(".logo-outernew").show();?

Answer:4

You can use the modulo (e.g. % sign) operator with a global variable to determine when hide or show your divs.

var count = 0;
$( document ).ready(function() {
    $(".logo-outer").show();
    setTimeout(function () {
        if(count % 2 == 0) {
            $(".logo-outer").hide();
            $(".logo-outernew").show();
        } else {
            $(".logo-outer").show();
            $(".logo-outernew").hide();
        }
        count++;
    }, 2000);
 });
Answer:5

By default hide your 2nd div and inside setTimeout hide your 1st dive and show your second div.

  $(".logo-outer").show();
  $(".logo-outernew").hide();
     setTimeout(function () {
         $(".logo-outer").hide();
         $(".logo-outernew").show();
     }, 2000);
.logo-outer {
    background:red;
    width: 50vw;
    height: 50vw;
}
.logo-outernew {
    background:green;
    width: 50vw;
    height: 50vw;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="logo-outer">
    <h1>1 div</h1>
</div>
<div class="logo-outernew">
    <h1>2 div</h1>
</div>
Answer:6

function swapImage() {
                $('.img02').fadeOut();
                $('.img01').fadeIn();
                setTimeout(function () {
                    $('.img02').fadeIn();
                    $('.img01').fadeOut();
                }, 2000);
                setTimeout(function () {
                    swapImage();
                },4000)
            }
            $(document).ready(function () {
                swapImage();
            });
.img01,
            .img02{
                width: 200px;
                height: 200px;
                position: absolute;
            }
            .img01{
                background: green;
            }
            .img02{
                background: red;
            }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="img01"></div>
<div class="img02" style="display: none;"></div>
Answer:7

Remove the console and un-comment the lines with hide and show function

     var time_to_display = 2000;
        var img1 = setInterval(function () {
        console.log("Img1");
        //          $(".logo-outer").hide();
          //      $(".logo-outernew").show();
           
                }, time_to_display * 2); 
                
        setTimeout(function(){
        var img2 = setInterval(function () {
        console.log("Img2");
            //       $(".logo-outernew").hide();
             //    $(".logo-outer").show();
                }, time_to_display * 2); 
        },2000);
        
Answer:8

How do I submit the form? I have a simple search bar and a search button. The following enters the search string, but the click event is not fired. When headless is set to false and I manully click ...

How do I submit the form? I have a simple search bar and a search button. The following enters the search string, but the click event is not fired. When headless is set to false and I manully click ...

  1. puppeteer submit form wait

I have an application which is built with node.js and react.js and is universal (or "isomorphic" as they were called before) and speaks with REST API to get data. In render method of some component ...

I have an application which is built with node.js and react.js and is universal (or "isomorphic" as they were called before) and speaks with REST API to get data. In render method of some component ...

I am using owl-carousel which is working pretty good when I load items directly. Although, when I try to load items through AJAX, those been rendered but not been displayed properly and not even ...

I am using owl-carousel which is working pretty good when I load items directly. Although, when I try to load items through AJAX, those been rendered but not been displayed properly and not even ...

  1. carousel doesn't slide
  2. carousel doesn't work
  3. carousel doesn't work bootstrap 4
  4. carousel doesn't start automatically
  5. bootstrap carousel doesn't work
  6. carousel does not resize
  7. bootstrap carousel doesn't slide
  8. owl carousel doesn't work
  9. bootstrap carousel doesn't slide automatically
  10. owl carousel doesn't show
  11. slick carousel doesn't work
  12. wallpaper carousel doesn't work
  13. materialize carousel doesn't work
  14. my carousel doesn't slide
  15. the carousel doesn't stop turning
  16. bootstrap carousel doesn't stop on hover
  17. owl carousel doesn't loop
  18. diptyque carousel doesn't work
  19. carousel slider doesn't work
  20. bootstrap carousel doesn't work angular

I created network in vis.js, but I need add icon to node, for example "plus", and then add handler to this icon. How I can do this?

I created network in vis.js, but I need add icon to node, for example "plus", and then add handler to this icon. How I can do this?

  1. nodejs icon
  2. nodes icon tweak - xf2
  3. xfa nodes icon tweak
  4. lymph nodes icon
  5. music notes icon
  6. server nodes icon
  7. music notes icon vector
  8. user coins icon
  9. node icon tweak
  10. xfa nodes icon tweak 3.0.0
  11. icon nodes mind map
  12. icon treeview nodes