Detect when Body Scroll hits top | bottom of element

前端 未结 2 814
失恋的感觉
失恋的感觉 2021-01-28 02:41

I\'m trying to detect using javascript and jquery when the window scroll hits the top of a selected element. I think I\'m making progress but still no results:

fiddle:

2条回答
  •  攒了一身酷
    2021-01-28 03:35

    $(window).scroll(function() {
        var targetScroll = $('.div').position().top;
        if($(window).scrollTop() > targetScroll) {
            alert('hey');
        }); // <=== Syntax Error: Closing Parenthese around an if block
    });
    

提交回复
热议问题