懒惰加载插件抛出Uncaught ReferenceError

lazy load plugin throwing Uncaught ReferenceError

本文关键字:Uncaught ReferenceError 插件 加载      更新时间:2023-09-26

我正在使用http://davidwalsh.name/lazyload-plugin当我运行它时,在控制台中给出一个错误,称为"Uncaught ReferenceError:Class is not defined"。我添加的代码如下

<script src="lazyload/Source/LazyLoad.js"></script>

然后下行

    <script>
/* do it! */
window.addEvent("domready",function() {
    var lazyloader = new LazyLoad();
});
</script>

和在身体的图像,我正在使用如下。

<img alt='"'" src='"lazyload/Assets/blank.gif'" data-src='"{$v['image_path']}'" style=width:auto;height:200px;max-height:200px>

其中$v['image_path']是动态的。是什么问题导致了那个错误,请帮帮我。

您缺少mootools库。在LazyLoad.js 之上添加mootools库

检查DEMO

 <script src="https://ajax.googleapis.com/ajax/libs/mootools/1.3.2/mootools.js"></script>
 <script src="lazyload/Source/LazyLoad.js"></script>

 <script>
   /* do it! */
    window.addEvent("domready",function() {
      var lazyloader = new LazyLoad();
    });
</script>

HTML。in为src和data-src设置相同的图像路径。

<img alt='"'" src='"{$v['image_path']}'" data-src='"{$v['image_path']}'" style=width:auto;height:200px;max-height:200px>