2016-03-08 121 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