Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var numberPicker = ({
- context: $('#1337haxxor'),
- minCount: 1,
- maxCount: 10,
- currentCount: 2,
- containerCurrent: null,
- containerNext: null,
- lock: false,
- clickUp: function() {
- if (!this.tryLock())
- return;
- this.currentCount++;
- if (this.currentCount > this.maxCount)
- this.currentCount = this.minCount;
- this.containerNext
- .text(this.currentCount)
- .css({left: "100%", opacity: 0, display: 'block'})
- .animate({left: "0%", opacity: 1});
- this.containerCurrent.animate(
- {left: "-100%", opacity: 0},
- {
- complete: (function(numPick) {
- return function() {
- numPick.unlock();
- $(this).css('display', 'none');
- }
- })(this)
- });
- temp = this.containerCurrent;
- this.containerCurrent = this.containerNext;
- this.containerNext = temp;
- },
- clickDown: function() {
- if (!this.tryLock())
- return;
- this.currentCount--;
- if (this.currentCount < this.minCount)
- this.currentCount = this.maxCount;
- this.containerNext
- .text(this.currentCount)
- .css({left: "-100%", opacity: 0, display: 'block'})
- .animate({left: "0%", opacity: 1});
- this.containerCurrent.animate(
- {left: "100%", opacity: 0},
- {
- complete: (function(numPick) {
- return function() {
- numPick.unlock();
- $(this).css('display', 'none');
- }
- })(this)
- });
- temp = this.containerCurrent;
- this.containerCurrent = this.containerNext;
- this.containerNext = temp;
- },
- tryLock: function() {
- if (this.lock)
- return false;
- return (this.lock = true);
- },
- unlock: function() {
- return (this.lock = false);
- },
- init: function() {
- this.containerNext = $(document.createElement('DIV'))
- .css('opacity', 0);
- this.containerCurrent = $(document.createElement('DIV'))
- .text(this.currentCount)
- .hide();
- this.context.append(this.containerCurrent,
- this.containerNext);
- this.containerCurrent.fadeIn();
- return this;
- }
- }).init();
- $("#count_down").click(function() {
- numberPicker.clickDown()
- });
- $("#count_up").click(function() {
- numberPicker.clickUp()
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement