Is there a performance issue with using very large background-position offsets?

泪湿孤枕 提交于 2019-12-07 00:02:48

问题


I'm building a progress bar control, and I'm working on the case where it doesn't actually show progress, but just spinning indicator of "something is happening". The design I have for it is basically alternating diagonal stripes, essentially a barber pole kinda like this, but "spinning":

With the hopes of offloading as much as I can to the rendering engine, I want to use CSS transitions for this. Supporting old browsers is not a concern for me.

So, my first idea was to basically do this:

.barber-pole {
    background-image: url(repeating-slice.png);

    /* set a very long (one hour!) transition on the background-position */
    transition: background-position 3600s linear 0s;
}

... and then, when it gets rendered to the screen, use Javascript to essentially do this:

myBarberPole.style.backgroundPosition = '-1000000px 0';

Are there any performance issues about:

  1. Transitioning for that long
  2. Having background-position: -1000000px 0 ?

Alternatively, do you have a better solution?


回答1:


I don't think there could be any performance issues. It's not because you use big numbers that they use more CPU or memory.




回答2:


In the absence of 'chaining' transitions to themselves (as far as I know there is no pure-CSS way of telling when the transition has finished) this could be a good solution, but as Justin says it requires a massive image! Is there any problem with using a good old-fashioned animated GIF?



来源:https://stackoverflow.com/questions/6344621/is-there-a-performance-issue-with-using-very-large-background-position-offsets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!