2016-03-08 98 views
0

不能得到这个插件来为我工作:https://github.com/morr/jquery.appear警报出现

使用Ajax是指从这个CDN到插件:http://cdnjs.cloudflare.com/ajax/libs/jquery.appear/0.3.3/jquery.appear.js

我在做什么错?我想报警时,DIV ID #footer的是在口中。

$.ajax({ 
    url: '//cdnjs.cloudflare.com/ajax/libs/jquery.appear/0.3.3/jquery.appear.js', 
    dataType: 'script', 
    cache: true, 
    success: function() { 
    $("#footer").appear(function() { 
      alert('I see a footer!'); 
     }); 
    } 
}); 

回答

2

使用插件的demo page使其工作。

  1. 首先使脚部构件能火“出现”事件,当它成为在视口中可见:

    $("#footer").appear(); 
    
  2. 后来听像这样的事件:

    $("body").on("appear", "#footer", function() { 
        // Do something... 
    }); 
    

代码片段:

$.ajax({ 
 
    url: '//cdnjs.cloudflare.com/ajax/libs/jquery.appear/0.3.3/jquery.appear.js', 
 
    dataType: 'script', 
 
    cache: true, 
 
    success: function() { 
 
    $("#footer").appear(); 
 

 
    $("body").on("appear", "#footer", function() { 
 
     alert('I see a footer!'); 
 
    }); 
 
    } 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<div style="height: 300px">Scroll down</div> 
 
<div id="footer">Footer</div>

+0

非常感谢你皮埃尔! – Hbaecklund