Created
April 1, 2017 13:12
-
-
Save Loiree/39b5169d097f57a92e2a829181df192c to your computer and use it in GitHub Desktop.
Counter — увеличивает число в выбранном объекте от заданного до нужного с анимацией
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<button onclick="ev.emit('counter:set', {obj: document.getElementsByClassName('counter')[0], countCur: 400, countNext: 700} )">Увеличить с 400 до 700</button> | |
<button onclick="ev.emit('counter:set', {obj: document.getElementsByClassName('counter')[0], countCur: 700, countNext: 400} )">Уменьшить с 700 до 400</button> | |
<div class="counter">400</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Увеличивает число в выбранном объекте от заданного до нужного с анимацией | |
// obj { | |
// obj: объект, в котором находится число, | |
// countCur: текущее значение, | |
// countNext: нужное значение | |
// } | |
var Counter = (function() { | |
return { | |
init: function() { | |
this.sub(); | |
}, | |
sub: function() { | |
var self = this; | |
ev.on("counter:set", function(obj) { | |
self.set(obj); | |
}); | |
}, | |
set: function(obj) { | |
var fn = function(progress) { | |
obj.obj.innerHTML = Math.floor(obj.countCur + progress * (obj.countNext - obj.countCur) ); | |
} | |
AnimHandler.init(fn, 400, "linear"); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment