我遇到Uncaught TypeError: Cannot read property 'top' of undefined
错误。有人可以帮助我了解什么是错误吗?
$("#section1").attr("data-background","#5A44A5");
$(window).on("scroll touchmove", function() {
if ($(document).scrollTop() >= $("#section1").position().top - 500) {
$('body').css('background', $("#section1").attr("data-background"));
}
});
<div id="section1" data-background="#5A44A5">