-
-
Save pavlo-bondarchuk/f56a72c39d87a073cdb20016af944385 to your computer and use it in GitHub Desktop.
count text
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
| document.addEventListener('DOMContentLoaded', function(event) { | |
| var $ = jQuery; | |
| if (!$('body').hasClass('wp-admin')) { | |
| $(window).on('loads scroll', function() { | |
| var element = $('.counter'); | |
| var top_of_element = element.offset().top; | |
| var bottom_of_element = element.offset().top + element.outerHeight(); | |
| var bottom_of_screen = $(window).scrollTop() + $(window).innerHeight(); | |
| var top_of_screen = $(window).scrollTop(); | |
| element.each(function() { | |
| if ((bottom_of_screen > top_of_element) && (top_of_screen < bottom_of_element) && !$(this).hasClass('animated')){ | |
| var $this = $(this), | |
| countTo = $this.attr('data-count'); | |
| $this.addClass('animated'); | |
| $({ countNum: $this.text()}).animate({ | |
| countNum: countTo | |
| }, | |
| { | |
| duration: 2500, | |
| easing:'linear', | |
| step: function() { | |
| $this.text(Math.floor(this.countNum)); | |
| }, | |
| complete: function() { | |
| $this.text(this.countNum); | |
| } | |
| }); | |
| } | |
| }); | |
| }); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment