Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
122 views
in Technique[技术] by (71.8m points)

javascript - Parallax stars on canvas. Is this too much for a website?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Lots of things here: You have to know your target audience for a website to know if you're doing too much on the sight. Targeting the wealthy? They probably have disposable income for good computers and can handle the task. Targetting as broad spectrum as possible? Make your site flex depending on the viewer. If you can't sustain a high frame rate, then fall back to a static image.

Next performance: You can get better performance from webgl, but you have to climb the mountain that is webgl.

Other performance: setInterval is bad practice for redraw loops. Use requestAnimationFrame to properly make changes on the main UI loop. If you need to reduce the frame rate, then skip some frames.

Canvas performance: Canvas is state based, things like fillStyle need not be reapplied if your state didn't change before, so take those out of your loop. You can micro-optimize your loop by not using an evaluated property in your conditional:

for (let i = 0, endi = stars.length; i < endi; ++i)

There's probably more little things you can do...

Next design: If it's truly an element that you believe makes your site stand out, then put in the effort to make the design work for everyone.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...