How can I make a div disappear when scrolling down 100px from the top?

前端 未结 1 1503
长发绾君心
长发绾君心 2021-01-05 22:16

I want to make a div disappear when I scroll down 100px and then reappear when within those 100px again from the top of the browser window. I don\'t want any animations just

相关标签:
1条回答
  • 2021-01-05 22:48

    You wont be able to do this in pure HTML or CSS, you'll need to resort to Javascript, your best bet is likely jQuery- as such it can be relatively easy to do this using:

    $(window).bind('scroll', function() {
         if ($(window).scrollTop() > 100) {
             $('#myDivId').hide();
         }
         else {
             $('#myDivId').show();
         }
    });
    
    0 讨论(0)
提交回复
热议问题