我正在使用与jQuery一起使用的lazyload函数。
我在我的liga.js文件中调用它,如下所示:
lazyload();
现在,在该页面的页脚我有:
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="code.jquery.com/ui/1.12.1/jquery-ui.min.js" ></script>
<script src="/includes/jquery.lazyload.min.js"></script>
<script src="/includes/liga.js"></script>
如您所见,我的liga.js文件位于列表的最后。
我也试过调用这个函数:
$(document).ready(function(){
lazyload();
...
我一直收到错误:
ReferenceError:未定义lazyload
这是为什么?
jQuery包装器的语法是$(selector).lazy()
...
$(function() {
$('.iam').lazy({
/* called before an element gets handled */
beforeLoad: function(element) {
var imageSrc = element.data('src');
console.log('image "' + imageSrc + '" is about to be loaded');
},
/* called after an element was successfully handled */
afterLoad: function(element) {
var imageSrc = element.data('src');
console.log('image "' + imageSrc + '" was loaded successfully');
},
/* called whenever an element could not be handled */
onError: function(element) {
var imageSrc = element.data('src');
console.log('image "' + imageSrc + '" could not be loaded');
},
/* called once all elements were handled */
onFinishedAll: function() {
console.log('finished loading all images');
}
});
});
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery.lazy/1.7.10/jquery.lazy.min.js"></script>
<img class="iam" data-src="http://www.ektoplazm.com/img/escape-into-the-mirror.jpg" width="640" height="640" />