Guest User

Untitled

a guest
Oct 17th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. var isScrolledIntoView = function(elem) {
  2. var $elem = $(elem);
  3. var $window = $(window);
  4. var docViewTop = $window.scrollTop();
  5. var docViewBottom = docViewTop + $window.height();
  6. var elemTop = $elem.offset().top;
  7. var elemBottom = elemTop + $elem.height();
  8. return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
  9. }
  10. var startCounter = function() {
  11. if ($('.count').length > 0) {
  12. if (isScrolledIntoView('.count:eq(0)') == true) {
  13. $(window).off("scroll", startCounter);
  14. $('.count').each(function() {
  15. var $this = $(this);
  16. $({
  17. Counter: 0
  18. }).animate({
  19. Counter: $this.data('count')
  20. }, {
  21. duration: 2000,
  22. easing: 'swing',
  23. step: function() {
  24. $this.text(Math.ceil(this.Counter));
  25. }
  26. });
  27. });
  28. }
  29. }
  30. };
Add Comment
Please, Sign In to add comment