javascript - .offset() 的值未定义
问题描述
我写了下面的函数
function test(use) {
var x = jQuery(window).scrollTop();
var y = x + jQuery(window).height();
console.log(typeof(jQuery(use)));
console.log(typeof(jQuery(use).offset()));
var z = jQuery(use).offset().top;
return ((y > z) && (z >= x - 100));
}
现在的问题是,每当调用此函数时,它都会给我一个错误,指出无法读取未定义的属性 top()。因此,问题在于变量 z。当我console.log()
对第一个语句使用语句时,即console.log(typeof (jQuery(use)));
我将值作为对象,但对于第二个语句,即console.log(typeof (jQuery(use).offset()));
我将值作为未定义。
谢谢
解决方案
推荐阅读
- php - Laravel 路由不附加任何前缀
- php - 从 php 运行 anaconda python 但其运行默认 python
- javascript - 更新道具时反应组件不重绘
- php - 在android 9中将我的android应用程序连接到php的问题
- java - 空指针异常和对象
- numpy - 这段代码中的 numpy sum 方法是多余的吗?
- c++ - 我的 C/C++ 程序在运行后立即关闭。必须使用 ConsolePauser.exe 运行
- r - 聚合频率分类表
- ruby-on-rails - RAILS:如何从具有分组的关联表中选择字段并从结果中创建哈希?
- image - 颤振应用程序中是否有任何用于图像编辑器的 api。我需要在图像中添加文本