javascript - Uncaught TypeError: Cannot read property 'top' of undefined -
i have following code , it's returning "uncaught typeerror: cannot read property 'top' of undefined" error in console , can't figure out why? code doing i'd do, i'd not return errors. can point me in 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 first scroll
event fires; include script @ end of page, wrap in $(document).ready
, or check .svgwrap
s.
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(); } });
Comments
Post a Comment