简体   繁体   English

如何使用jQuery(或JavaScript)将关键帧设置为50%?

[英]How to set keyframes 50% using jquery(or javascript)?

I'm making time(second) bar. 我正在制作时间(秒)栏。

When opening page, bar's width should be (second/60)*100%. 打开页面时,栏的宽度应为(秒/ 60)* 100%。

I want to start from 50% instead of the beginning. 我想从50%开始而不是从开始。

Using jquery or javascript. 使用jQuery或JavaScript。

Please tell me about. 请告诉我有关。

                    #loader {
                    width: 50%;
                    height: 5px;
                    background-color: #fff;
                    animation-name: loadingBar;
                    animation-duration: 60s;
                    animation-timing-function: steps(60, end);
                    animation-direction: normal;
                    animation-play-state: running;
                    animation-iteration-count: infinite;

                    @keyframes loadingBar {
                        0% {
                            width: 0%;                            
                        }

                        100% {
                            width: 100%;
                        }
                    }

Hi Could you try this overwrite the style existing.And also remove it if required to get old behavior 嗨,您可以尝试覆盖现有的样式吗?如果需要获得旧样式也可以将其删除

  function setStyle() {
      let st = document.createElement("style");
      st.id="RemoveMeInFuture";
        const stext=`@keyframes loadingBar {
                        50% {
                            width: 0%;                            
                        }

                        100% {
                            width: 100%;
                        }
                    }

                    .foo{background:red}`;
      document.querySelector("head").appendChild(st);
      if (st.styleSheet){
  // This is required for IE8 and below.
  st.styleSheet.cssText = stext;
} else {
  st.appendChild(document.createTextNode(stext));
}
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM