-2

I am trying to prevent the page from refreshing when the "replayclick" is clicked. Id like it to just run the set time in and out for the "#cmp" elements. I am sure its something simple I am missing.

$("#replayclick").click(function(event) {
    event.preventDefault(); 
    setTimeout(function () {
        $("#replay").fadeOut();
    }, 0);
    setTimeout(function () {
        $("#cmp1").fadeIn();
    }, 0);
    setTimeout(function () {
        $("#cmp1").hide();
    }, 2000);
    setTimeout(function () {
        $("#cmp2").fadeIn();
    }, 2000);
    setTimeout(function () {
        $("#cmp2").hide();
    }, 4000);
    setTimeout(function () {
        $("#cmp3").fadeIn();
    }, 4000);
    setTimeout(function () {
        $("#cmp3").hide();
    }, 6000);
    setTimeout(function () {
        $("#cmp4").fadeIn();
    }, 6000);
    setTimeout(function () {
        $("#cmp4").hide();
    },8000);
    setTimeout(function () {
        $("#replay").fadeIn();
    }, 8000);

});

HTML

<div class="cm-bodyphoto">
  <div id="replay" class="cm-image-container"><a id="replayclick" href=""><img class="cm-image" src="replay.png" height="155" width="298"></a></div>
  <div id="cmp1" class="cm-image-container"><a href="#"><img class="cm-image" src="slide-1.png" height="155" width="298"></a></div>
  <div id="cmp2" class="cm-image-container"><a href="#"><img class="cm-image" src="slide-2.png" height="155" width="298"></a></div>
  <div id="cmp3" class="cm-image-container"><a href="#"><img class="cm-image" src="slide-3.png" height="155" width="298"></a></div>
  <div id="cmp4" class="cm-image-container"><a href="#"><img class="cm-image" src="slide-4.png" height="155" width="298"></a></div></div> 
Spencer Wieczorek
  • 21,229
  • 7
  • 44
  • 54
aclm
  • 21
  • 2

1 Answers1

1

Ok I figured it out. It might not be the cleanest solution but it works for me. Looks like i forgot an additional }); at the end.

Thank you guys for helping get the wheels turning :)

$(window).load(function(){
    setTimeout(function () {
        $("#cmp1").hide();
    }, 2000);
    setTimeout(function () {
        $("#cmp2").fadeIn();
    }, 2000);
    setTimeout(function () {
        $("#cmp2").hide();
    }, 4000);
    setTimeout(function () {
        $("#cmp3").fadeIn();
    }, 4000);
    setTimeout(function () {
        $("#cmp3").hide();
    }, 6000);
    setTimeout(function () {
        $("#cmp4").fadeIn();
    }, 6000);
    setTimeout(function () {
        $("#replay").fadeIn();
    }, 8000);
 $("#replayclick").click(function(event) {
    event.preventDefault(); 
    setTimeout(function () {
        $("#replay").fadeOut();
    }, 0);
    setTimeout(function () {
        $("#cmp4").hide();
    }, 0);
    setTimeout(function () {
        $("#cmp1").show();
    }, 0);
    setTimeout(function () {
        $("#cmp1").hide();
    }, 2000);
    setTimeout(function () {
        $("#cmp2").fadeIn();
    }, 2000);
    setTimeout(function () {
        $("#cmp2").hide();
    }, 4000);
    setTimeout(function () {
        $("#cmp3").fadeIn();
    }, 4000);
    setTimeout(function () {
        $("#cmp3").hide();
    }, 6000);
    setTimeout(function () {
        $("#cmp4").fadeIn();
    }, 6000);
    setTimeout(function () {
        $("#replay").fadeIn();
    }, 8000);
});
});
aclm
  • 21
  • 2