javascript – 使用jquery 3.1.1的stellar.js未捕获TypeError

在单个页面中,我只包括jQuery 3.1.1和 stellar.js的视差滚动效果,但是当我尝试tu使用它作为$(window).stellar();我在控制台中收到这个错误
Uncaught TypeError: f.getClientRects is not a function (jquery-3.1.1.min.js:4)

我尝试使用迁移插件,如许多答案中所建议的,但不能解决我的问题.

该片段只是为了向您显示错误.

$(function(){
  $('.main').stellar();
 });
<div class="main">
  <div class="slide"></div>
  <div class="slide"></div>
  <div class="slide"></div>
</div>

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar.js/0.6.2/jquery.stellar.min.js"></script>

解决方法

由于这段代码,stellar.js失败了
$(window).load(function() {
                var oldLeft = self._getScrollLeft(),oldTop = self._getScrollTop();

                self._setScrollLeft(oldLeft + 1);
                self._setScrollTop(oldTop + 1);

                self._setScrollLeft(oldLeft);
                self._setScrollTop(oldTop);
            });

在jquery 3.0中,加载事件被删除.你可以改为on(‘load’,function {});

$(window).on('load',function() {
                    var oldLeft = self._getScrollLeft(),oldTop = self._getScrollTop();

                    self._setScrollLeft(oldLeft + 1);
                    self._setScrollTop(oldTop + 1);

                    self._setScrollLeft(oldLeft);
                    self._setScrollTop(oldTop);
                });

这是一个“工作”的小提琴:https://jsfiddle.net/y19x160g/1/,通过工作,我只是说不会再发错了.

P.S:我不知道这个库是用什么的.

在那个js小提琴中,我刚从当前的GitHub项目:https://github.com/markdalgleish/stellar.js/blob/master/src/jquery.stellar.js复制了未经简化的脚本
修改负载事件.

其他参考:https://api.jquery.com/load-event/ – 请参阅弃用

相关文章

jQuery表单验证提交:前台验证一(图文+视频)
jQuery表单验证提交:前台验证二(图文+视频)
jQuery如何实时监听获取input输入框的值
JQuery怎么判断元素是否存在
jQuery如何实现定时重定向
jquery如何获取复选框选中的值