123456789101112131415161718192021222324 |
- // 3s 把宽度从100px变为640px,即增加540px
- // 60帧/s, 3s 180帧,每次变化3px
- let curWidth = 100
- const maxWidth = 1000
- const $div1 = $("#div1")
- // setTimeout
- // function animate(){
- // curWidth += 3
- // $div1.css('width', curWidth)
- // if(curWidth < maxWidth) {
- // setTimeout(animate, 16.7); // 得自己控制时间
- // }
- // }
- // animate()
- function animate(){
- curWidth += 3
- $div1.css('width', curWidth)
- if(curWidth < maxWidth) {
- window.requestAnimationFrame(animate)
- }
- }
- animate()
|