Skip to content
This repository has been archived by the owner on Apr 2, 2019. It is now read-only.

Initiate animation on viewport #150

Open
Ignitis opened this issue Nov 16, 2017 · 1 comment
Open

Initiate animation on viewport #150

Ignitis opened this issue Nov 16, 2017 · 1 comment

Comments

@Ignitis
Copy link

Ignitis commented Nov 16, 2017

Hi,

Is there any way I can initiate the odometer animation as soon as the element is in the viewport?

I need to use odometer on a component which is on the 3rd fold of the webpage. I want it to animate as soon as that component is visible in the viewport.

Thank you.
Pri

@jason-mares
Copy link

jason-mares commented Apr 13, 2018

It's possible using jQuery to initiate when the odometer class gets into the viewport:

`
$(document).ready(function(){

$.fn.isInViewport = function() {
  var elementTop = $(this).offset().top;
  var elementBottom = elementTop + $(this).outerHeight();

  var viewportTop = $(window).scrollTop();
  var viewportBottom = viewportTop + $(window).height();

  return elementBottom > viewportTop && elementTop < viewportBottom;
};

$(window).on('resize scroll', function() {
  $('.odometer').each(function() {
    if ($(this).isInViewport()) {
        
      setTimeout(function(){
        $('.odometer').html(240000);
      }, 0);
    } else {
    }
  });
});

});
`

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants