Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var isScrolledIntoView = function(elem) {
- var $elem = $(elem);
- var $window = $(window);
- var docViewTop = $window.scrollTop();
- var docViewBottom = docViewTop + $window.height();
- var elemTop = $elem.offset().top;
- var elemBottom = elemTop + $elem.height();
- return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
- }
- var startCounter = function() {
- if ($('.count').length > 0) {
- if (isScrolledIntoView('.count:eq(0)') == true) {
- $(window).off("scroll", startCounter);
- $('.count').each(function() {
- var $this = $(this);
- $({
- Counter: 0
- }).animate({
- Counter: $this.data('count')
- }, {
- duration: 2000,
- easing: 'swing',
- step: function() {
- $this.text(Math.ceil(this.Counter));
- }
- });
- });
- }
- }
- };
Add Comment
Please, Sign In to add comment