Skip to content

Commit bf0de3e

Browse files
committed
fix sir support
1 parent 3f3fff8 commit bf0de3e

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

dist/vue-count-to.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vue-count-to.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-count-to",
33
"description": "It's a vue component that will count to a target number at a specified duration",
4-
"version": "1.0.6",
4+
"version": "1.0.10",
55
"author": "Pan <[email protected]>",
66
"main": "dist/vue-count-to.min.js",
77
"scripts": {

src/requestAnimationFrame.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,45 @@
11
let lastTime = 0
22
const prefixes = 'webkit moz ms o'.split(' ') // 各浏览器前缀
3+
34
let requestAnimationFrame
45
let cancelAnimationFrame
5-
let prefix
6-
const isServer = typeof window === 'undefined'
76

8-
if (!isServer) {
7+
const isServer = typeof window === 'undefined'
8+
if (isServer) {
9+
requestAnimationFrame = function() {
10+
return
11+
}
12+
cancelAnimationFrame = function() {
13+
return
14+
}
15+
} else {
916
requestAnimationFrame = window.requestAnimationFrame
1017
cancelAnimationFrame = window.cancelAnimationFrame
11-
// 通过遍历各浏览器前缀,来得到requestAnimationFrame和cancelAnimationFrame在当前浏览器的实现形式
18+
let prefix
19+
// 通过遍历各浏览器前缀,来得到requestAnimationFrame和cancelAnimationFrame在当前浏览器的实现形式
1220
for (let i = 0; i < prefixes.length; i++) {
1321
if (requestAnimationFrame && cancelAnimationFrame) { break }
1422
prefix = prefixes[i]
1523
requestAnimationFrame = requestAnimationFrame || window[prefix + 'RequestAnimationFrame']
1624
cancelAnimationFrame = cancelAnimationFrame || window[prefix + 'CancelAnimationFrame'] || window[prefix + 'CancelRequestAnimationFrame']
1725
}
18-
}
1926

20-
// 如果当前浏览器不支持requestAnimationFrame和cancelAnimationFrame,则会退到setTimeout
21-
if (!requestAnimationFrame || !cancelAnimationFrame) {
22-
requestAnimationFrame = function(callback) {
23-
const currTime = new Date().getTime()
24-
// 为了使setTimteout的尽可能的接近每秒60帧的效果
25-
const timeToCall = Math.max(0, 16 - (currTime - lastTime))
26-
const id = window.setTimeout(() => {
27-
callback(currTime + timeToCall)
28-
}, timeToCall)
29-
lastTime = currTime + timeToCall
30-
return id
31-
}
27+
// 如果当前浏览器不支持requestAnimationFrame和cancelAnimationFrame,则会退到setTimeout
28+
if (!requestAnimationFrame || !cancelAnimationFrame) {
29+
requestAnimationFrame = function(callback) {
30+
const currTime = new Date().getTime()
31+
// 为了使setTimteout的尽可能的接近每秒60帧的效果
32+
const timeToCall = Math.max(0, 16 - (currTime - lastTime))
33+
const id = window.setTimeout(() => {
34+
callback(currTime + timeToCall)
35+
}, timeToCall)
36+
lastTime = currTime + timeToCall
37+
return id
38+
}
3239

33-
cancelAnimationFrame = function(id) {
34-
window.clearTimeout(id)
40+
cancelAnimationFrame = function(id) {
41+
window.clearTimeout(id)
42+
}
3543
}
3644
}
3745

0 commit comments

Comments
 (0)