Question

I'm using jquery.knob plugin in a website is very easy to implement. I animate it and everything is ok, but i would like animate effect start when I scroll to specific section of the web: for example when I scroll to #about section.

Anybody Knows if is that posible?

thanks in advance

Was it helpful?

Solution

There are several jQuery-Plugins to check if an element is scrolled into view, e.g. jquery.inview.

Example Setup:

<input type='text' class='dial' value='0' data-number='100' />
<div style="height: 300px">scroll down</div>
<div class="startKnob">start</div>

Initialize the knob and write a function for the animation. Just bind inview to the element that's out of the viewport and should start the animation as soon as it's in view.

$(function () {
  $('.dial').knob({
     min: '0',
     max: '100',
     readOnly: true
  });
});

startKnob =  function() {
  $('.dial').animate({
      value: $('.dial').data('number')
  },{
      duration: 950,
      easing: 'swing',
      progress: function () {
                 $('.dial').val(Math.round(this.value)).trigger('change');
     }
 });
}

$('.startKnob').bind('inview', startKnob);

Working example here: Start knob animation when specific element is in view

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top