jquery - 声明的函数 ($.fn) 不是函数
问题描述
我试图让一个乐蒂动画开始,当在视野中时。我声明了一个函数
$.fn.isOnScreen = function(){
var win = $(window);
var viewport = {
top : win.scrollTop(),
left : win.scrollLeft()
};
viewport.right = viewport.left + win.width();
viewport.bottom = viewport.top + win.height();
var bounds = this.offset();
bounds.right = bounds.left + this.outerWidth();
bounds.bottom = bounds.top + this.outerHeight();
return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom));
};
然后调用它
jQuery(document).ready(function(){
jQuery(window).scroll(function(){
if (jQuery('#circle-anim').isOnScreen()) {
var circle = lottie.loadAnimation({
container: document.getElementById("anim-badge-1"),
renderer: "svg",
loop: true,
autoplay: true,
path: "PATH TO JSON" // the path to the animation json
});
circle.playSegments(
[
[0, 30],
[162, 575]
],
true
);
var anim;
anim = lottie.loadAnimation(circle);
alert("in viewport!");
} else {
console.log('not visible');
}
});
});
我一滚动我就得到
未捕获的类型错误:jQuery(...).isOnScreen 不是
(index):102 处的函数在调度 (jquery-3.5.1.min.dc5e7f18c8.js?site=60ec2441446e3d0b9389fa3c:2) 在 v.handle (jquery-3.5 .1.min.dc5e7f18c8.js?site=60ec2441446e3d0b9389fa3c:2)
任何想法为什么isOnScreen不起作用?
解决方案
推荐阅读
- python - 无法将嵌套框架切换到主页
- python - 熊猫数据框输出为文本而不是标准格式
- c++ - 不能在其他 .cpp 文件中使用单例静态函数:“未定义的引用”
- javascript - 我无法弄清楚为什么我的 gulp 文件没有观看我的 html 文件?
- c# - 如何将局部变量升级为扩展方法
- docusignapi - 带有公式/计算字段的 DocuSign RESTful API
- c# - 如何为 SoapClient 分配特定的主机和 URI
- php - 如何从职业解决方案表中的用户那里获取角色?
- c# - NamedClient 没有按预期给出响应
- python - 读取 RFID 卡时如何在画布中显示图像?