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
  • 51,385
  • 23
  • 99
  • 140
Kuba Żukowski
  • 603
  • 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
  • 935
  • 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
  • 7,550
  • 10
  • 40
  • 79
0
$('body').scroll(function(){
  var scrollTop = $('body').scrollTop();
  var topOfCount =  $('#count-repairs-all').offset().top;
  if(scrollTop>topOfCount){
    // dosomeThing
  }
});
Tuhin
  • 2,960
  • 1
  • 9
  • 21