onclick hide previous images slowly and show new











up vote
0
down vote

favorite












Is it possible to use this code and first hide old images and show newlike here.I wanted to create a var where I could collect previous images names and probably change timePassed to -timePassed but couldn’t achieve proper effect. If you can, advise, please, pure js.



    function animate(draw,duration){
var start = performance.now();
requestAnimationFrame(function animate(time){
var timePassed = time- start;
if(timePassed > duration) timePassed = duration;
draw(timePassed), 1000;

if(timePassed < duration){
requestAnimationFrame(animate);
}
});
}

for(var i=0; i<table.length; i++){

table[i].addEventListener("click", function(event){


clearAll();
var tar = event.target;
targetName=tar.classList;
var name = tar.className;

targetName.add("active");

animate(function(timePassed){
if(tar.className == name +" active"){

head.style.display = "block";
document.querySelector(".maintext").innerHTML=name;
// images appear on the page trough their names
mainIMG.src = name+"1.jpg";
odd1IMG.src = name+"2.jpg";
odd2IMG.src = name+"3.jpg";
}

mainIMG.style.top = timePassed / 3 + "px";
odd1IMG.style.top = timePassed / 3 + "px";
odd2IMG.style.top = timePassed / 3+ "px";


}, 900);



});


}



function clearAll(){
for(var i=0; i<table.length; i++){
table[i].classList.remove("active");
}
}









share|improve this question


























    up vote
    0
    down vote

    favorite












    Is it possible to use this code and first hide old images and show newlike here.I wanted to create a var where I could collect previous images names and probably change timePassed to -timePassed but couldn’t achieve proper effect. If you can, advise, please, pure js.



        function animate(draw,duration){
    var start = performance.now();
    requestAnimationFrame(function animate(time){
    var timePassed = time- start;
    if(timePassed > duration) timePassed = duration;
    draw(timePassed), 1000;

    if(timePassed < duration){
    requestAnimationFrame(animate);
    }
    });
    }

    for(var i=0; i<table.length; i++){

    table[i].addEventListener("click", function(event){


    clearAll();
    var tar = event.target;
    targetName=tar.classList;
    var name = tar.className;

    targetName.add("active");

    animate(function(timePassed){
    if(tar.className == name +" active"){

    head.style.display = "block";
    document.querySelector(".maintext").innerHTML=name;
    // images appear on the page trough their names
    mainIMG.src = name+"1.jpg";
    odd1IMG.src = name+"2.jpg";
    odd2IMG.src = name+"3.jpg";
    }

    mainIMG.style.top = timePassed / 3 + "px";
    odd1IMG.style.top = timePassed / 3 + "px";
    odd2IMG.style.top = timePassed / 3+ "px";


    }, 900);



    });


    }



    function clearAll(){
    for(var i=0; i<table.length; i++){
    table[i].classList.remove("active");
    }
    }









    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Is it possible to use this code and first hide old images and show newlike here.I wanted to create a var where I could collect previous images names and probably change timePassed to -timePassed but couldn’t achieve proper effect. If you can, advise, please, pure js.



          function animate(draw,duration){
      var start = performance.now();
      requestAnimationFrame(function animate(time){
      var timePassed = time- start;
      if(timePassed > duration) timePassed = duration;
      draw(timePassed), 1000;

      if(timePassed < duration){
      requestAnimationFrame(animate);
      }
      });
      }

      for(var i=0; i<table.length; i++){

      table[i].addEventListener("click", function(event){


      clearAll();
      var tar = event.target;
      targetName=tar.classList;
      var name = tar.className;

      targetName.add("active");

      animate(function(timePassed){
      if(tar.className == name +" active"){

      head.style.display = "block";
      document.querySelector(".maintext").innerHTML=name;
      // images appear on the page trough their names
      mainIMG.src = name+"1.jpg";
      odd1IMG.src = name+"2.jpg";
      odd2IMG.src = name+"3.jpg";
      }

      mainIMG.style.top = timePassed / 3 + "px";
      odd1IMG.style.top = timePassed / 3 + "px";
      odd2IMG.style.top = timePassed / 3+ "px";


      }, 900);



      });


      }



      function clearAll(){
      for(var i=0; i<table.length; i++){
      table[i].classList.remove("active");
      }
      }









      share|improve this question













      Is it possible to use this code and first hide old images and show newlike here.I wanted to create a var where I could collect previous images names and probably change timePassed to -timePassed but couldn’t achieve proper effect. If you can, advise, please, pure js.



          function animate(draw,duration){
      var start = performance.now();
      requestAnimationFrame(function animate(time){
      var timePassed = time- start;
      if(timePassed > duration) timePassed = duration;
      draw(timePassed), 1000;

      if(timePassed < duration){
      requestAnimationFrame(animate);
      }
      });
      }

      for(var i=0; i<table.length; i++){

      table[i].addEventListener("click", function(event){


      clearAll();
      var tar = event.target;
      targetName=tar.classList;
      var name = tar.className;

      targetName.add("active");

      animate(function(timePassed){
      if(tar.className == name +" active"){

      head.style.display = "block";
      document.querySelector(".maintext").innerHTML=name;
      // images appear on the page trough their names
      mainIMG.src = name+"1.jpg";
      odd1IMG.src = name+"2.jpg";
      odd2IMG.src = name+"3.jpg";
      }

      mainIMG.style.top = timePassed / 3 + "px";
      odd1IMG.style.top = timePassed / 3 + "px";
      odd2IMG.style.top = timePassed / 3+ "px";


      }, 900);



      });


      }



      function clearAll(){
      for(var i=0; i<table.length; i++){
      table[i].classList.remove("active");
      }
      }






      javascript






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      Sabina

      31




      31





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349309%2fonclick-hide-previous-images-slowly-and-show-new%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349309%2fonclick-hide-previous-images-slowly-and-show-new%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Ottavio Pratesi

          Tricia Helfer

          15 giugno