看到元素时调用JS函数

时间:2015-06-09 07:40:14

标签: javascript jquery

当我看到显示的元素(滚动到元素)时,我想调用函数(动画)。我试试这个:

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

但它不起作用。我无法找到任何插件。

3 个答案:

答案 0 :(得分:0)

您可以尝试:

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');
});

答案 1 :(得分:0)

如果您使用的是NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory NSString *filePath = [documentsPath stringByAppendingPathComponent:@"image.png"]; //Add the file name NSData *pngData = [NSData dataWithContentsOfFile:filePath]; UIImage *image = [UIImage imageWithData:pngData]; ,可以试试这个

jQuery

查看jQuery DOCS

答案 2 :(得分:0)

$('body').scroll(function(){
  var scrollTop = $('body').scrollTop();
  var topOfCount =  $('#count-repairs-all').offset().top;
  if(scrollTop>topOfCount){
    // dosomeThing
  }
});