简体   繁体   English

未捕获的TypeError:无法读取未定义的属性“ top”

[英]Uncaught TypeError: Cannot read property 'top' of undefined

I have the following code and it's returning a "Uncaught TypeError: Cannot read property 'top' of undefined" error in the console and I can't figure out why? 我有以下代码,并且在控制台中返回“ Uncaught TypeError:无法读取未定义的属性'top'”错误,我不知道为什么? The code is actually doing what I'd like it to do, but I'd like for it to not return any errors. 该代码实际上在执行我想做的事情,但是我希望它不返回任何错误。 Can someone point me in the right direction? 有人可以指出我正确的方向吗?

var sig = false;
$(window).on('scroll', function () {
    var sigTop = $('.svgWrap').offset().top - 500;
    var winTop = $(window).scrollTop();
    if (sigTop < winTop && !sig) {
        sig = true;
        animateSignature();
    }
})

.svgWrap might not exist when the first scroll event fires; 当第一个scroll事件触发时, .svgWrap可能不存在; include the script at the end of the page, wrap it in a $(document).ready , or check for .svgWrap s. 在页面末尾包含脚本,将其包装在$(document).ready ,或检查.svgWrap

var sig = false;

$(window).on('scroll', function () {
    var svgWrap = $('.svgWrap');

    if (!svgWrap.length) {
        return;
    }

    var sigTop = svgWrap.offset().top - 500;
    var winTop = $(window).scrollTop();
    if (sigTop < winTop && !sig) {
        sig = true;
        animateSignature();
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的类型错误:无法读取未定义的属性“顶部” - Uncaught TypeError: Cannot read property ‘top’ of undefined 未捕获的TypeError:无法读取未定义的属性“ top” - Uncaught TypeError: Cannot read property 'top' of undefined 未捕获的TypeError:无法读取未定义的属性“ top” - Uncaught TypeError: Cannot read property 'top' of undefined 未捕获的类型错误:无法读取未定义的属性“顶部” - Uncaught TypeError: Cannot read property 'top' of undefined 购物车飞未捕获的TypeError:无法读取未定义的属性“顶部” - Cart to Fly Uncaught TypeError: Cannot read property 'top' of undefined 图表 JS 错误:未捕获的类型错误:无法读取未定义的属性“顶部” - Chart JS Error : Uncaught TypeError: Cannot read property 'top' of undefined jQuery Uncaught TypeError:无法读取未定义的属性“ top” - jQuery Uncaught TypeError: Cannot read property 'top' of undefined Uncaught TypeError:无法读取未定义的属性“ top”-滚动错误? - Uncaught TypeError: Cannot read property 'top' of undefined - Scrolling error? 未捕获的TypeError:无法读取未定义的属性“ top”(jQuery) - Uncaught TypeError: Cannot read property 'top' of undefined (jquery) 控制台错误:未捕获TypeError:无法读取未定义的属性“顶部” - Console Error: Uncaught TypeError: Cannot read property 'top' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM