<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(function() {
$.fn.Timer = function Timer(obj) {
var def = {
from: 5000,
duration: 5000,
to: 0,
callback: null
};
var opt = $.extend({}, def, obj);
return this.each(function(indx, el) {
$(el).queue(function() {
el.n = opt.from;
$(el).dequeue()
});
$(el).animate({
n: opt.to
}, {
easing: "linear",
duration: opt.duration,
step: function(now, fx) {
$(fx.elem).html(now | 0)
},
complete: opt.callback
})
})
};
$("#slider").Timer({
callback: function() {
$(this).css({
color: "red"
})
}
}).Timer({
duration: 2E4,
callback: function() {
$(this).text("End")
}
})
});
</script>
</head>
<body>
<div id="slider"></div>
</body>
</html>