Last active
August 29, 2015 14:05
-
-
Save A/7d3c4b29ab0d846e4eb6 to your computer and use it in GitHub Desktop.
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
| var Gallery = function($el, path, count) { | |
| this.iterator = 0; | |
| this.count = count; | |
| this.$el = $el; | |
| this.path = path; | |
| this.$img = this.$el.find('js-img'); | |
| // bind clicks | |
| this.$el.find('js-next-img').on('click', this.next.bind(this)); | |
| this.$el.find('js-prev-img').on('click', this.prev.bind(this)); | |
| } | |
| Gallery.prototype.next = function () { | |
| this.iterator++; | |
| this.show() | |
| } | |
| Gallery.prototype.prev = function () { | |
| this.iterator--; | |
| this.show() | |
| } | |
| Gallery.prototype.show = function () { | |
| this.iterator > this.count && (this.iterator = 0); | |
| this.iterator < 0 && (this.iterator = count); | |
| this.$img.src = this.path.replace('%num%', this.iterator); | |
| } | |
| // use: | |
| new Gallery($('.my-gallery')', images/256/255_%num%-01.png', 13); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment