Call function on scroll only once

前端 未结 4 1839
悲&欢浪女
悲&欢浪女 2021-01-01 23:48

I got a question regarding a function that will be called if the object is within my screen. But when the object is within my screen the function is been called and a alert

4条回答
  •  佛祖请我去吃肉
    2021-01-01 23:55

    $(window).on('scroll', function() {
      if ($(document).scrollTop() >= $(document).height() / 100) {
        $("#spopup").show("slow");
        $(window).off('scroll');
      } else {
        $("#spopup").hide("slow");
      }
    });
    
    function closeSPopup() {
      $('#spopup').hide('slow');
    }
    

    worked for me

提交回复
热议问题