+ 3

Are there any ways to change CSS style dynamically with JS besides this? And is this a good way? 😀

https://code.sololearn.com/W7SThNwQfpu6/?ref=app

1st Jun 2019, 3:47 PM
Merida
Merida - avatar
5 ответов
+ 6
1. 有的 requestAnimationFrame() 是比 setInterval() 更適合做動畫的,因為會自動按照最佳時機補上下一格。 例子: https://code.sololearn.com/WZV2FsGPRwr6/?ref=app 詳情請參閱這篇文章: https://hacks.mozilla.org/2011/08/animating-with-javascript-from-setinterval-to-requestanimationframe/ 2. 不是好方法 Calvin 說的只用CSS才是好方法。 除非你在編遊戲,動畫與遊戲參數掛勾。
1st Jun 2019, 4:59 PM
Gordon
Gordon - avatar
+ 6
Animation that not require any logic to control, is better to use css to control it https://code.sololearn.com/WU5LZViaGKXY/?ref=app
1st Jun 2019, 4:14 PM
Calviղ
Calviղ - avatar
+ 1
You add stylesheet in js and change it with js! function test() { document.getElementById('idname').style.background = 'green' ; }
1st Jun 2019, 3:53 PM
CodeFu
CodeFu - avatar
+ 1
U can use classlist.add, first make a class with a new style the classlist.add it using js see link for more info. https://alligator.io/js/classlist/
1st Jun 2019, 4:02 PM
Shawaine
Shawaine - avatar
+ 1
Gordon 感谢(・ω< )★
2nd Jun 2019, 1:23 AM
Merida
Merida - avatar