Skip to content

Commit 75855dd

Browse files
authored
chore(dom): add requestAnimationFrame shorthand util (bootstrap-vue#2747)
1 parent d083385 commit 75855dd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/utils/dom.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,23 @@ export const position = el => /* istanbul ignore next: getBoundingClientRect() d
289289
left: _offset.left - parentOffset.left - parseFloat(elStyles.marginLeft)
290290
}
291291
}
292+
293+
// requestAnimationFrame convenience method
294+
let rAF = cb => {
295+
// Fallback, but not a true polyfill.
296+
// But all browsers we support (other than Opera Mini) support rAF
297+
// without a polyfil
298+
/* istanbul ignore next */
299+
return setTimeout(cb, 16)
300+
}
301+
if (inBrowser) {
302+
/* istanbul ignore next */
303+
rAF =
304+
window.requestAnimationFrame ||
305+
window.webkitRequestAnimationFrame ||
306+
window.mozRequestAnimationFrame ||
307+
window.msRequestAnimationFrame ||
308+
window.oRequestAnimationFrame ||
309+
rAF
310+
}
311+
export const requestAF = rAF

0 commit comments

Comments
 (0)