0

I want call to function (animation) when I see element on display (scroll to element). I try this:

<script type="text/javascript">
    $('#count-repairs-all').on('show', function() { 
        alert('test'); 
    })
</script>

But it doesn't work. I can't find any plugin for this.

Pete
  • 57,112
  • 28
  • 117
  • 166
Kuba Żukowski
  • 653
  • 3
  • 11
  • 16

3 Answers3

0

You can try it as:

function isVisible(){
   //do something
alert(1);
}

//bind the  event with element
$('#contentDiv').bind('isVisible', isVisible);

//show div and trigger custom event in callback when div is visible
$('#contentDiv').show('slow', function(){
    $(this).trigger('isVisible');
});
Vivek Gupta
  • 955
  • 4
  • 7
0

If you are using jQuery you can try this

var element = $('#yourDiv')
if(element.is(':visible')){
//Do some stuff
}
else{
//Do something else
}

Check out jQuery DOCS

Abhinav
  • 8,028
  • 12
  • 48
  • 89
0
$('body').scroll(function(){
  var scrollTop = $('body').scrollTop();
  var topOfCount =  $('#count-repairs-all').offset().top;
  if(scrollTop>topOfCount){
    // dosomeThing
  }
});
Tuhin
  • 3,335
  • 2
  • 16
  • 27