jquery knob animate on load section

孤街醉人 提交于 2019-12-13 01:26:25

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/19604962/jquery-knob-animate-on-load-section

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!