Created
August 9, 2016 14:08
-
-
Save culttm/ef0dd3a01ab603e4d84d01885ea6d382 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
| (function ($) { | |
| var AnimatedEl = (function(){ | |
| var AnimatedEl = function (o) { | |
| this.el = $(o.el); | |
| this.animationType = $(o.el).data('action'); | |
| this.checkInterval = o.checkInterval; | |
| this.timeout = null; | |
| this.init(); | |
| }; | |
| AnimatedEl.prototype.init = function () { | |
| this.setupListeners(); | |
| }; | |
| AnimatedEl.prototype.setupListeners = function () { | |
| var self = this; | |
| self.el.on('mouseenter', function () { | |
| self.run($(this)); | |
| }).on('mouseleave', function () { | |
| clearInterval(self.timeout) | |
| }); | |
| }; | |
| AnimatedEl.prototype.run = function (el) { | |
| var self = this; | |
| this.timeout = setInterval(function () { | |
| el.addClass(self.animationType); | |
| }, self.checkInterval); | |
| el.on("webkitAnimationEnd mozAnimationEnd oAnimationEnd animationEnd", function(e){ | |
| self.stop(el); | |
| }); | |
| }; | |
| AnimatedEl.prototype.stop = function (el) { | |
| el.removeClass(this.animationType); | |
| }; | |
| return AnimatedEl; | |
| })(); | |
| $.each($('.js-anim-el'), function (i, el) { | |
| new AnimatedEl({ | |
| el: el, | |
| checkInterval: 200 | |
| }); | |
| }) | |
| })(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment