Can I have fill-mode between frames?












1















I'm trying to make a complex animation, so I made the next simple example to ilustrate my problem.



The next code tries to make an object rotate, change its color at 50% of animation and keep it until 100%,
the problem I got is that when it changes from 50% to 100% it doesn't keep the previous keyframe (50%), it becomes transpatent again at 100%.



I've worked with some animation software like blender or animate cc and the default behavior is to keep values of the
properties set in the last keyframe unless you actively change it to something else.



I know that I can set the background property again to red at 100%. but for a real complex animation that would mean repeating A LOT of values,
I'm also aware of the "animation-fill-mode" property which keeps the final state of animation if it is set to "forward",
so I though that if I did that in each step it would behave as I wish but it didn't work :(



Is there a good workaround for this problem without having to repeat each property on every frame?
Can I change the default behaviour?



Note: I thought that if a property is not set on each frame it would default to the initial value (0% frame),
however I didn't set any "transform:rotate" property at 50% and it's not defaulted to 0%'s value, since it interpolates the value between 0% and 100%,
so I have no idea how this really works :/ , some clarification on why does this happen would be really appreceated



    .test{
all: unset;
animation-name: rotate_and_change_color;
animation-duration: 3s;
animation-fill-mode: forwards;
animation-timing-function: linear;
animation-direction: normal;
}



@keyframes rotate_and_change_color{
0%{transform: rotate(0deg);
animation-fill-mode: forwards;
}
50%{
background: red;
animation-fill-mode: forwards;
}
100%{transform: rotate(360deg);
animation-fill-mode: forwards;
}
}









share|improve this question





























    1















    I'm trying to make a complex animation, so I made the next simple example to ilustrate my problem.



    The next code tries to make an object rotate, change its color at 50% of animation and keep it until 100%,
    the problem I got is that when it changes from 50% to 100% it doesn't keep the previous keyframe (50%), it becomes transpatent again at 100%.



    I've worked with some animation software like blender or animate cc and the default behavior is to keep values of the
    properties set in the last keyframe unless you actively change it to something else.



    I know that I can set the background property again to red at 100%. but for a real complex animation that would mean repeating A LOT of values,
    I'm also aware of the "animation-fill-mode" property which keeps the final state of animation if it is set to "forward",
    so I though that if I did that in each step it would behave as I wish but it didn't work :(



    Is there a good workaround for this problem without having to repeat each property on every frame?
    Can I change the default behaviour?



    Note: I thought that if a property is not set on each frame it would default to the initial value (0% frame),
    however I didn't set any "transform:rotate" property at 50% and it's not defaulted to 0%'s value, since it interpolates the value between 0% and 100%,
    so I have no idea how this really works :/ , some clarification on why does this happen would be really appreceated



        .test{
    all: unset;
    animation-name: rotate_and_change_color;
    animation-duration: 3s;
    animation-fill-mode: forwards;
    animation-timing-function: linear;
    animation-direction: normal;
    }



    @keyframes rotate_and_change_color{
    0%{transform: rotate(0deg);
    animation-fill-mode: forwards;
    }
    50%{
    background: red;
    animation-fill-mode: forwards;
    }
    100%{transform: rotate(360deg);
    animation-fill-mode: forwards;
    }
    }









    share|improve this question



























      1












      1








      1








      I'm trying to make a complex animation, so I made the next simple example to ilustrate my problem.



      The next code tries to make an object rotate, change its color at 50% of animation and keep it until 100%,
      the problem I got is that when it changes from 50% to 100% it doesn't keep the previous keyframe (50%), it becomes transpatent again at 100%.



      I've worked with some animation software like blender or animate cc and the default behavior is to keep values of the
      properties set in the last keyframe unless you actively change it to something else.



      I know that I can set the background property again to red at 100%. but for a real complex animation that would mean repeating A LOT of values,
      I'm also aware of the "animation-fill-mode" property which keeps the final state of animation if it is set to "forward",
      so I though that if I did that in each step it would behave as I wish but it didn't work :(



      Is there a good workaround for this problem without having to repeat each property on every frame?
      Can I change the default behaviour?



      Note: I thought that if a property is not set on each frame it would default to the initial value (0% frame),
      however I didn't set any "transform:rotate" property at 50% and it's not defaulted to 0%'s value, since it interpolates the value between 0% and 100%,
      so I have no idea how this really works :/ , some clarification on why does this happen would be really appreceated



          .test{
      all: unset;
      animation-name: rotate_and_change_color;
      animation-duration: 3s;
      animation-fill-mode: forwards;
      animation-timing-function: linear;
      animation-direction: normal;
      }



      @keyframes rotate_and_change_color{
      0%{transform: rotate(0deg);
      animation-fill-mode: forwards;
      }
      50%{
      background: red;
      animation-fill-mode: forwards;
      }
      100%{transform: rotate(360deg);
      animation-fill-mode: forwards;
      }
      }









      share|improve this question
















      I'm trying to make a complex animation, so I made the next simple example to ilustrate my problem.



      The next code tries to make an object rotate, change its color at 50% of animation and keep it until 100%,
      the problem I got is that when it changes from 50% to 100% it doesn't keep the previous keyframe (50%), it becomes transpatent again at 100%.



      I've worked with some animation software like blender or animate cc and the default behavior is to keep values of the
      properties set in the last keyframe unless you actively change it to something else.



      I know that I can set the background property again to red at 100%. but for a real complex animation that would mean repeating A LOT of values,
      I'm also aware of the "animation-fill-mode" property which keeps the final state of animation if it is set to "forward",
      so I though that if I did that in each step it would behave as I wish but it didn't work :(



      Is there a good workaround for this problem without having to repeat each property on every frame?
      Can I change the default behaviour?



      Note: I thought that if a property is not set on each frame it would default to the initial value (0% frame),
      however I didn't set any "transform:rotate" property at 50% and it's not defaulted to 0%'s value, since it interpolates the value between 0% and 100%,
      so I have no idea how this really works :/ , some clarification on why does this happen would be really appreceated



          .test{
      all: unset;
      animation-name: rotate_and_change_color;
      animation-duration: 3s;
      animation-fill-mode: forwards;
      animation-timing-function: linear;
      animation-direction: normal;
      }



      @keyframes rotate_and_change_color{
      0%{transform: rotate(0deg);
      animation-fill-mode: forwards;
      }
      50%{
      background: red;
      animation-fill-mode: forwards;
      }
      100%{transform: rotate(360deg);
      animation-fill-mode: forwards;
      }
      }






      css css3 css-animations keyframe






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 1:14









      Temani Afif

      73.1k94081




      73.1k94081










      asked Nov 22 '18 at 1:03









      adrian Diazadrian Diaz

      813




      813
























          1 Answer
          1






          active

          oldest

          votes


















          1














          One way is to consider multiple animations where you can easily control each property:






          .test {
          animation-name: rotate, change_color;
          animation-duration: 3s;
          animation-fill-mode: forwards;
          animation-timing-function: linear;
          animation-direction: normal;

          width:200px;
          height:200px;
          }

          @keyframes rotate {
          0% {
          transform: rotate(0deg);
          }
          100% {
          transform: rotate(360deg);
          }
          }

          @keyframes change_color {
          50%,
          100% {
          background: red;
          }
          }

          <div class="test">
          </div>





          Concerning your note this apply to only the last and first state where if you don't specify any value the computed value will be considered (the initial one or the one defined in the style of the element)




          If a 0% or from keyframe is not specified, then the user agent constructs a 0% keyframe using the computed values of the properties being animated. If a 100% or to keyframe is not specified, then the user agent constructs a 100% keyframe using the computed values of the properties being animated.ref




          For the other states, you have in fact an interpolation considering the value you have defined and the one automatically done (in case you didn't define the 0% and 100%)






          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%2f53422539%2fcan-i-have-fill-mode-between-frames%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









            1














            One way is to consider multiple animations where you can easily control each property:






            .test {
            animation-name: rotate, change_color;
            animation-duration: 3s;
            animation-fill-mode: forwards;
            animation-timing-function: linear;
            animation-direction: normal;

            width:200px;
            height:200px;
            }

            @keyframes rotate {
            0% {
            transform: rotate(0deg);
            }
            100% {
            transform: rotate(360deg);
            }
            }

            @keyframes change_color {
            50%,
            100% {
            background: red;
            }
            }

            <div class="test">
            </div>





            Concerning your note this apply to only the last and first state where if you don't specify any value the computed value will be considered (the initial one or the one defined in the style of the element)




            If a 0% or from keyframe is not specified, then the user agent constructs a 0% keyframe using the computed values of the properties being animated. If a 100% or to keyframe is not specified, then the user agent constructs a 100% keyframe using the computed values of the properties being animated.ref




            For the other states, you have in fact an interpolation considering the value you have defined and the one automatically done (in case you didn't define the 0% and 100%)






            share|improve this answer






























              1














              One way is to consider multiple animations where you can easily control each property:






              .test {
              animation-name: rotate, change_color;
              animation-duration: 3s;
              animation-fill-mode: forwards;
              animation-timing-function: linear;
              animation-direction: normal;

              width:200px;
              height:200px;
              }

              @keyframes rotate {
              0% {
              transform: rotate(0deg);
              }
              100% {
              transform: rotate(360deg);
              }
              }

              @keyframes change_color {
              50%,
              100% {
              background: red;
              }
              }

              <div class="test">
              </div>





              Concerning your note this apply to only the last and first state where if you don't specify any value the computed value will be considered (the initial one or the one defined in the style of the element)




              If a 0% or from keyframe is not specified, then the user agent constructs a 0% keyframe using the computed values of the properties being animated. If a 100% or to keyframe is not specified, then the user agent constructs a 100% keyframe using the computed values of the properties being animated.ref




              For the other states, you have in fact an interpolation considering the value you have defined and the one automatically done (in case you didn't define the 0% and 100%)






              share|improve this answer




























                1












                1








                1







                One way is to consider multiple animations where you can easily control each property:






                .test {
                animation-name: rotate, change_color;
                animation-duration: 3s;
                animation-fill-mode: forwards;
                animation-timing-function: linear;
                animation-direction: normal;

                width:200px;
                height:200px;
                }

                @keyframes rotate {
                0% {
                transform: rotate(0deg);
                }
                100% {
                transform: rotate(360deg);
                }
                }

                @keyframes change_color {
                50%,
                100% {
                background: red;
                }
                }

                <div class="test">
                </div>





                Concerning your note this apply to only the last and first state where if you don't specify any value the computed value will be considered (the initial one or the one defined in the style of the element)




                If a 0% or from keyframe is not specified, then the user agent constructs a 0% keyframe using the computed values of the properties being animated. If a 100% or to keyframe is not specified, then the user agent constructs a 100% keyframe using the computed values of the properties being animated.ref




                For the other states, you have in fact an interpolation considering the value you have defined and the one automatically done (in case you didn't define the 0% and 100%)






                share|improve this answer















                One way is to consider multiple animations where you can easily control each property:






                .test {
                animation-name: rotate, change_color;
                animation-duration: 3s;
                animation-fill-mode: forwards;
                animation-timing-function: linear;
                animation-direction: normal;

                width:200px;
                height:200px;
                }

                @keyframes rotate {
                0% {
                transform: rotate(0deg);
                }
                100% {
                transform: rotate(360deg);
                }
                }

                @keyframes change_color {
                50%,
                100% {
                background: red;
                }
                }

                <div class="test">
                </div>





                Concerning your note this apply to only the last and first state where if you don't specify any value the computed value will be considered (the initial one or the one defined in the style of the element)




                If a 0% or from keyframe is not specified, then the user agent constructs a 0% keyframe using the computed values of the properties being animated. If a 100% or to keyframe is not specified, then the user agent constructs a 100% keyframe using the computed values of the properties being animated.ref




                For the other states, you have in fact an interpolation considering the value you have defined and the one automatically done (in case you didn't define the 0% and 100%)






                .test {
                animation-name: rotate, change_color;
                animation-duration: 3s;
                animation-fill-mode: forwards;
                animation-timing-function: linear;
                animation-direction: normal;

                width:200px;
                height:200px;
                }

                @keyframes rotate {
                0% {
                transform: rotate(0deg);
                }
                100% {
                transform: rotate(360deg);
                }
                }

                @keyframes change_color {
                50%,
                100% {
                background: red;
                }
                }

                <div class="test">
                </div>





                .test {
                animation-name: rotate, change_color;
                animation-duration: 3s;
                animation-fill-mode: forwards;
                animation-timing-function: linear;
                animation-direction: normal;

                width:200px;
                height:200px;
                }

                @keyframes rotate {
                0% {
                transform: rotate(0deg);
                }
                100% {
                transform: rotate(360deg);
                }
                }

                @keyframes change_color {
                50%,
                100% {
                background: red;
                }
                }

                <div class="test">
                </div>






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 22 '18 at 1:13

























                answered Nov 22 '18 at 1:07









                Temani AfifTemani Afif

                73.1k94081




                73.1k94081
































                    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%2f53422539%2fcan-i-have-fill-mode-between-frames%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

                    "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                    Alcedinidae

                    RAC Tourist Trophy