forked from 0x2620/oxjs
use requestAnimationFrame for loading icon if available
This commit is contained in:
parent
f043242640
commit
4c54a294f6
2 changed files with 46 additions and 20 deletions
31
index.js
31
index.js
|
|
@ -353,23 +353,36 @@ Ox.load(/^https?:\/\/(www\.)?oxjs\.org\//.test(
|
|||
rotate: function() {
|
||||
var css, deg = 0,
|
||||
previousTime = +new Date(),
|
||||
interval = setInterval(function() {
|
||||
var currentTime = +new Date(),
|
||||
delta = (currentTime - previousTime) / 1000,
|
||||
loadingIcon = document.getElementById('loadingIcon');
|
||||
if (loadingIcon) {
|
||||
interval;
|
||||
function step() {
|
||||
var currentTime = +new Date(),
|
||||
delta = (currentTime - previousTime) / 1000,
|
||||
loadingIcon = document.getElementById('loadingIcon'),
|
||||
next = Math.round((deg + delta * 360) % 360 / 30) * 30;
|
||||
if (loadingIcon) {
|
||||
if (deg != next) {
|
||||
previousTime = currentTime;
|
||||
deg = Math.round((deg + delta * 360) % 360 / 30) * 30;
|
||||
deg = next;
|
||||
css = 'rotate(' + deg + 'deg)';
|
||||
loadingIcon.style.MozTransform = css;
|
||||
loadingIcon.style.MSTransform = css;
|
||||
loadingIcon.style.OTransform = css;
|
||||
loadingIcon.style.WebkitTransform = css;
|
||||
loadingIcon.style.transform = css;
|
||||
} else {
|
||||
clearInterval(interval);
|
||||
}
|
||||
}, 83);
|
||||
if (window.requestAnimationFrame !== undefined) {
|
||||
window.requestAnimationFrame(step);
|
||||
}
|
||||
} else if (window.requestAnimationFrame === undefined) {
|
||||
clearInterval(interval);
|
||||
|
||||
}
|
||||
};
|
||||
if (window.requestAnimationFrame !== undefined) {
|
||||
window.requestAnimationFrame(step);
|
||||
} else {
|
||||
interval = setInterval(step, 83);
|
||||
}
|
||||
},
|
||||
setTheme: function(theme) {
|
||||
app.user.theme = theme;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue