You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
809 B

/**
* mui animation
*/
(function($, window) {
/**
* scrollTo
*/
$.scrollTo = function(scrollTop, duration, callback) {
duration = duration || 1000;
var scroll = function(duration) {
if (duration <= 0) {
window.scrollTo(0, scrollTop);
callback && callback();
return;
}
var distaince = scrollTop - window.scrollY;
setTimeout(function() {
window.scrollTo(0, window.scrollY + distaince / duration * 10);
scroll(duration - 10);
}, 16.7);
};
scroll(duration);
};
$.animationFrame = function(cb) {
var args, isQueued, context;
return function() {
args = arguments;
context = this;
if (!isQueued) {
isQueued = true;
requestAnimationFrame(function() {
cb.apply(context, args);
isQueued = false;
});
}
};
};
})(mui, window);