How can I play a css animation in b.html when a button is clicked in a.html and still use the same javascript file?How can I format numbers as currency string in JavaScript?Trigger a button click with JavaScript on the Enter key in a text boxHow can I upload files asynchronously?How can I merge properties of two JavaScript objects dynamically?How can I convert a string to boolean in JavaScript?How can I know which radio button is selected via jQuery?How can I get query string values in JavaScript?How do I include a JavaScript file in another JavaScript file?How can I display a JavaScript object?How can I add new array elements at the beginning of an array in Javascript?

Is using haveibeenpwned to validate password strength rational?

Subfigures with pgfplots

Best way to deal with non-developers in a scrum team

Why doesn't Adrian Toomes give up Spider-Man's identity?

How do I write "Show, Don't Tell" as a person with Asperger Syndrome?

Russian equivalents of "no love lost"

"You've got another thing coming" - translation into French

Hottest Possible Hydrogen-Fusing Stars

Inconsistent behavior of compiler optimization of unused string

What can I, as a user, do about offensive reviews in App Store?

Did the ending really happen in Baby Driver?

How to project 3d image in the planes xy, xz, yz?

Why would future John risk sending back a T-800 to save his younger self?

How water is heavier than petrol eventhough its molecular weight less than petrol?

What does the "c." listed under weapon length mean?

How to officially communicate to a non-responsive colleague?

How can drunken, homicidal elves successfully conduct a wild hunt?

Where does "0 packages can be updated." come from?

Compiling c files on ubuntu and using the executable on Windows

Do simulator games use a realistic trajectory to get into orbit?

Find duplicated column value in CSV

Is it possible to 'live off the sea'

What risks are there when you clear your cookies instead of logging off?

Genetic limitations to learn certain instruments



How can I play a css animation in b.html when a button is clicked in a.html and still use the same javascript file?


How can I format numbers as currency string in JavaScript?Trigger a button click with JavaScript on the Enter key in a text boxHow can I upload files asynchronously?How can I merge properties of two JavaScript objects dynamically?How can I convert a string to boolean in JavaScript?How can I know which radio button is selected via jQuery?How can I get query string values in JavaScript?How do I include a JavaScript file in another JavaScript file?How can I display a JavaScript object?How can I add new array elements at the beginning of an array in Javascript?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















Im making a website where users can personalize their pizza. If the button deliverPizzaButton is clicked I want to redirect the user to another html page where an animation will be played which will let them know the pizza is on their way.



This is what I have now in my javascript, it is redirecting to the second HTML but the animation does not play in the second html



var pizzaDelivererImg = document.getElementById('pizzaDeliverer');


function changeHTML()
if (deliverPizzaButton.classList == ('readyToDeliver')) // when all the steps are completed the button will change color and the button can be clicked
window.location.href = 'pizzaAnimation.html';
playAnimation();



deliverPizzaButton.addEventListener('click', changeHTML);

function playAnimation()
if (window.location.href == 'pizzaAnimation.html')
pizzaDelivererImg.classList.add('letTheDelivererDrive');




CSS:



.letTheDelivererDrive 
animation: animationFrames ease-in-out 4s;
animation-iteration-count: 1;
transform-origin: 50% 50%;
animation-fill-mode: forwards;
/*when the spec is finished*/
-webkit-animation: animationFrames ease-in-out 4s;
-webkit-animation-iteration-count: 1;
-webkit-transform-origin: 50% 50%;
-webkit-animation-fill-mode: forwards;
/*Chrome 16+, Safari 4+*/
-moz-animation: animationFrames ease-in-out 4s;
-moz-animation-iteration-count: 1;
-moz-transform-origin: 50% 50%;
-moz-animation-fill-mode: forwards;
/*FF 5+*/
-o-animation: animationFrames ease-in-out 4s;
-o-animation-iteration-count: 1;
-o-transform-origin: 50% 50%;
-o-animation-fill-mode: forwards;
/*Not implemented yet*/
-ms-animation: animationFrames ease-in-out 4s;
-ms-animation-iteration-count: 1;
-ms-transform-origin: 50% 50%;
-ms-animation-fill-mode: forwards;
/*IE 10+*/


@keyframes animationFrames
0%
transform: translate(-355px, -31px);

100%
transform: translate(309px, -26px);



@-moz-keyframes animationFrames
0%
-moz-transform: translate(-355px, -31px);

100%
-moz-transform: translate(309px, -26px);



@-webkit-keyframes animationFrames
0%
-webkit-transform: translate(-355px, -31px);

100%
-webkit-transform: translate(309px, -26px);



@-o-keyframes animationFrames
0%
-o-transform: translate(-355px, -31px);

100%
-o-transform: translate(309px, -26px);



@-ms-keyframes animationFrames
0%
-ms-transform: translate(-355px, -31px);

100%
-ms-transform: translate(309px, -26px);




HTML 1 (index.html) (where the button will be clicked to redirect):



<img id="pizzaDeliverer" src="img/pizzadeliverer.png" alt="pizza deliverer">


HTML 2 (pizzaAnimation.html) (where the animation will be played):



it is linked to the same css and script as in index.html



<img id="pizzaDeliverer" src="img/pizzadeliverer.png" alt="pizza deliverer">









share|improve this question
























  • You are redirecting to another page and playing the animation on other page, do it on the same page

    – window.document
    Mar 24 at 16:25

















1















Im making a website where users can personalize their pizza. If the button deliverPizzaButton is clicked I want to redirect the user to another html page where an animation will be played which will let them know the pizza is on their way.



This is what I have now in my javascript, it is redirecting to the second HTML but the animation does not play in the second html



var pizzaDelivererImg = document.getElementById('pizzaDeliverer');


function changeHTML()
if (deliverPizzaButton.classList == ('readyToDeliver')) // when all the steps are completed the button will change color and the button can be clicked
window.location.href = 'pizzaAnimation.html';
playAnimation();



deliverPizzaButton.addEventListener('click', changeHTML);

function playAnimation()
if (window.location.href == 'pizzaAnimation.html')
pizzaDelivererImg.classList.add('letTheDelivererDrive');




CSS:



.letTheDelivererDrive 
animation: animationFrames ease-in-out 4s;
animation-iteration-count: 1;
transform-origin: 50% 50%;
animation-fill-mode: forwards;
/*when the spec is finished*/
-webkit-animation: animationFrames ease-in-out 4s;
-webkit-animation-iteration-count: 1;
-webkit-transform-origin: 50% 50%;
-webkit-animation-fill-mode: forwards;
/*Chrome 16+, Safari 4+*/
-moz-animation: animationFrames ease-in-out 4s;
-moz-animation-iteration-count: 1;
-moz-transform-origin: 50% 50%;
-moz-animation-fill-mode: forwards;
/*FF 5+*/
-o-animation: animationFrames ease-in-out 4s;
-o-animation-iteration-count: 1;
-o-transform-origin: 50% 50%;
-o-animation-fill-mode: forwards;
/*Not implemented yet*/
-ms-animation: animationFrames ease-in-out 4s;
-ms-animation-iteration-count: 1;
-ms-transform-origin: 50% 50%;
-ms-animation-fill-mode: forwards;
/*IE 10+*/


@keyframes animationFrames
0%
transform: translate(-355px, -31px);

100%
transform: translate(309px, -26px);



@-moz-keyframes animationFrames
0%
-moz-transform: translate(-355px, -31px);

100%
-moz-transform: translate(309px, -26px);



@-webkit-keyframes animationFrames
0%
-webkit-transform: translate(-355px, -31px);

100%
-webkit-transform: translate(309px, -26px);



@-o-keyframes animationFrames
0%
-o-transform: translate(-355px, -31px);

100%
-o-transform: translate(309px, -26px);



@-ms-keyframes animationFrames
0%
-ms-transform: translate(-355px, -31px);

100%
-ms-transform: translate(309px, -26px);




HTML 1 (index.html) (where the button will be clicked to redirect):



<img id="pizzaDeliverer" src="img/pizzadeliverer.png" alt="pizza deliverer">


HTML 2 (pizzaAnimation.html) (where the animation will be played):



it is linked to the same css and script as in index.html



<img id="pizzaDeliverer" src="img/pizzadeliverer.png" alt="pizza deliverer">









share|improve this question
























  • You are redirecting to another page and playing the animation on other page, do it on the same page

    – window.document
    Mar 24 at 16:25













1












1








1








Im making a website where users can personalize their pizza. If the button deliverPizzaButton is clicked I want to redirect the user to another html page where an animation will be played which will let them know the pizza is on their way.



This is what I have now in my javascript, it is redirecting to the second HTML but the animation does not play in the second html



var pizzaDelivererImg = document.getElementById('pizzaDeliverer');


function changeHTML()
if (deliverPizzaButton.classList == ('readyToDeliver')) // when all the steps are completed the button will change color and the button can be clicked
window.location.href = 'pizzaAnimation.html';
playAnimation();



deliverPizzaButton.addEventListener('click', changeHTML);

function playAnimation()
if (window.location.href == 'pizzaAnimation.html')
pizzaDelivererImg.classList.add('letTheDelivererDrive');




CSS:



.letTheDelivererDrive 
animation: animationFrames ease-in-out 4s;
animation-iteration-count: 1;
transform-origin: 50% 50%;
animation-fill-mode: forwards;
/*when the spec is finished*/
-webkit-animation: animationFrames ease-in-out 4s;
-webkit-animation-iteration-count: 1;
-webkit-transform-origin: 50% 50%;
-webkit-animation-fill-mode: forwards;
/*Chrome 16+, Safari 4+*/
-moz-animation: animationFrames ease-in-out 4s;
-moz-animation-iteration-count: 1;
-moz-transform-origin: 50% 50%;
-moz-animation-fill-mode: forwards;
/*FF 5+*/
-o-animation: animationFrames ease-in-out 4s;
-o-animation-iteration-count: 1;
-o-transform-origin: 50% 50%;
-o-animation-fill-mode: forwards;
/*Not implemented yet*/
-ms-animation: animationFrames ease-in-out 4s;
-ms-animation-iteration-count: 1;
-ms-transform-origin: 50% 50%;
-ms-animation-fill-mode: forwards;
/*IE 10+*/


@keyframes animationFrames
0%
transform: translate(-355px, -31px);

100%
transform: translate(309px, -26px);



@-moz-keyframes animationFrames
0%
-moz-transform: translate(-355px, -31px);

100%
-moz-transform: translate(309px, -26px);



@-webkit-keyframes animationFrames
0%
-webkit-transform: translate(-355px, -31px);

100%
-webkit-transform: translate(309px, -26px);



@-o-keyframes animationFrames
0%
-o-transform: translate(-355px, -31px);

100%
-o-transform: translate(309px, -26px);



@-ms-keyframes animationFrames
0%
-ms-transform: translate(-355px, -31px);

100%
-ms-transform: translate(309px, -26px);




HTML 1 (index.html) (where the button will be clicked to redirect):



<img id="pizzaDeliverer" src="img/pizzadeliverer.png" alt="pizza deliverer">


HTML 2 (pizzaAnimation.html) (where the animation will be played):



it is linked to the same css and script as in index.html



<img id="pizzaDeliverer" src="img/pizzadeliverer.png" alt="pizza deliverer">









share|improve this question
















Im making a website where users can personalize their pizza. If the button deliverPizzaButton is clicked I want to redirect the user to another html page where an animation will be played which will let them know the pizza is on their way.



This is what I have now in my javascript, it is redirecting to the second HTML but the animation does not play in the second html



var pizzaDelivererImg = document.getElementById('pizzaDeliverer');


function changeHTML()
if (deliverPizzaButton.classList == ('readyToDeliver')) // when all the steps are completed the button will change color and the button can be clicked
window.location.href = 'pizzaAnimation.html';
playAnimation();



deliverPizzaButton.addEventListener('click', changeHTML);

function playAnimation()
if (window.location.href == 'pizzaAnimation.html')
pizzaDelivererImg.classList.add('letTheDelivererDrive');




CSS:



.letTheDelivererDrive 
animation: animationFrames ease-in-out 4s;
animation-iteration-count: 1;
transform-origin: 50% 50%;
animation-fill-mode: forwards;
/*when the spec is finished*/
-webkit-animation: animationFrames ease-in-out 4s;
-webkit-animation-iteration-count: 1;
-webkit-transform-origin: 50% 50%;
-webkit-animation-fill-mode: forwards;
/*Chrome 16+, Safari 4+*/
-moz-animation: animationFrames ease-in-out 4s;
-moz-animation-iteration-count: 1;
-moz-transform-origin: 50% 50%;
-moz-animation-fill-mode: forwards;
/*FF 5+*/
-o-animation: animationFrames ease-in-out 4s;
-o-animation-iteration-count: 1;
-o-transform-origin: 50% 50%;
-o-animation-fill-mode: forwards;
/*Not implemented yet*/
-ms-animation: animationFrames ease-in-out 4s;
-ms-animation-iteration-count: 1;
-ms-transform-origin: 50% 50%;
-ms-animation-fill-mode: forwards;
/*IE 10+*/


@keyframes animationFrames
0%
transform: translate(-355px, -31px);

100%
transform: translate(309px, -26px);



@-moz-keyframes animationFrames
0%
-moz-transform: translate(-355px, -31px);

100%
-moz-transform: translate(309px, -26px);



@-webkit-keyframes animationFrames
0%
-webkit-transform: translate(-355px, -31px);

100%
-webkit-transform: translate(309px, -26px);



@-o-keyframes animationFrames
0%
-o-transform: translate(-355px, -31px);

100%
-o-transform: translate(309px, -26px);



@-ms-keyframes animationFrames
0%
-ms-transform: translate(-355px, -31px);

100%
-ms-transform: translate(309px, -26px);




HTML 1 (index.html) (where the button will be clicked to redirect):



<img id="pizzaDeliverer" src="img/pizzadeliverer.png" alt="pizza deliverer">


HTML 2 (pizzaAnimation.html) (where the animation will be played):



it is linked to the same css and script as in index.html



<img id="pizzaDeliverer" src="img/pizzadeliverer.png" alt="pizza deliverer">






javascript css-animations addeventlistener window.location






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 16:18







Dušanka Prvulovic

















asked Mar 24 at 16:12









Dušanka PrvulovicDušanka Prvulovic

165




165












  • You are redirecting to another page and playing the animation on other page, do it on the same page

    – window.document
    Mar 24 at 16:25

















  • You are redirecting to another page and playing the animation on other page, do it on the same page

    – window.document
    Mar 24 at 16:25
















You are redirecting to another page and playing the animation on other page, do it on the same page

– window.document
Mar 24 at 16:25





You are redirecting to another page and playing the animation on other page, do it on the same page

– window.document
Mar 24 at 16:25












1 Answer
1






active

oldest

votes


















0














The problem is you're trying to run code after the browser has been told to unload the current page and head to another one.



 window.location.href = 'pizzaAnimation.html';
playAnimation(); //<-- this won't happen because of ^^


So in effect you're telling it to play the animation on the first page, not the second one. What you need to do instead is modify the JS to act onload for the second page, and then run the animation.



function playAnimation() 
pizzaDelivererImg.classList.add('letTheDelivererDrive');

if (window.location.href == 'pizzaAnimation.html') playAnimation();


Also note that



deliverPizzaButton.classList == ('readyToDeliver')


...is not a proper, scalable implementation of classList. Better would be:



deliverPizzaButton.classList.contains('readyToDeliver')





share|improve this answer























    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',
    autoActivateHeartbeat: false,
    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%2f55325814%2fhow-can-i-play-a-css-animation-in-b-html-when-a-button-is-clicked-in-a-html-and%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The problem is you're trying to run code after the browser has been told to unload the current page and head to another one.



     window.location.href = 'pizzaAnimation.html';
    playAnimation(); //<-- this won't happen because of ^^


    So in effect you're telling it to play the animation on the first page, not the second one. What you need to do instead is modify the JS to act onload for the second page, and then run the animation.



    function playAnimation() 
    pizzaDelivererImg.classList.add('letTheDelivererDrive');

    if (window.location.href == 'pizzaAnimation.html') playAnimation();


    Also note that



    deliverPizzaButton.classList == ('readyToDeliver')


    ...is not a proper, scalable implementation of classList. Better would be:



    deliverPizzaButton.classList.contains('readyToDeliver')





    share|improve this answer



























      0














      The problem is you're trying to run code after the browser has been told to unload the current page and head to another one.



       window.location.href = 'pizzaAnimation.html';
      playAnimation(); //<-- this won't happen because of ^^


      So in effect you're telling it to play the animation on the first page, not the second one. What you need to do instead is modify the JS to act onload for the second page, and then run the animation.



      function playAnimation() 
      pizzaDelivererImg.classList.add('letTheDelivererDrive');

      if (window.location.href == 'pizzaAnimation.html') playAnimation();


      Also note that



      deliverPizzaButton.classList == ('readyToDeliver')


      ...is not a proper, scalable implementation of classList. Better would be:



      deliverPizzaButton.classList.contains('readyToDeliver')





      share|improve this answer

























        0












        0








        0







        The problem is you're trying to run code after the browser has been told to unload the current page and head to another one.



         window.location.href = 'pizzaAnimation.html';
        playAnimation(); //<-- this won't happen because of ^^


        So in effect you're telling it to play the animation on the first page, not the second one. What you need to do instead is modify the JS to act onload for the second page, and then run the animation.



        function playAnimation() 
        pizzaDelivererImg.classList.add('letTheDelivererDrive');

        if (window.location.href == 'pizzaAnimation.html') playAnimation();


        Also note that



        deliverPizzaButton.classList == ('readyToDeliver')


        ...is not a proper, scalable implementation of classList. Better would be:



        deliverPizzaButton.classList.contains('readyToDeliver')





        share|improve this answer













        The problem is you're trying to run code after the browser has been told to unload the current page and head to another one.



         window.location.href = 'pizzaAnimation.html';
        playAnimation(); //<-- this won't happen because of ^^


        So in effect you're telling it to play the animation on the first page, not the second one. What you need to do instead is modify the JS to act onload for the second page, and then run the animation.



        function playAnimation() 
        pizzaDelivererImg.classList.add('letTheDelivererDrive');

        if (window.location.href == 'pizzaAnimation.html') playAnimation();


        Also note that



        deliverPizzaButton.classList == ('readyToDeliver')


        ...is not a proper, scalable implementation of classList. Better would be:



        deliverPizzaButton.classList.contains('readyToDeliver')






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 16:23









        UtkanosUtkanos

        22.8k63463




        22.8k63463





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55325814%2fhow-can-i-play-a-css-animation-in-b-html-when-a-button-is-clicked-in-a-html-and%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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해