Uncaught TypeError:无法读取未定义的属性“ top”?

时间:2019-07-16 09:12:35

标签: javascript jquery html

我遇到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">

0 个答案:

没有答案