Show div after scrolling 100px from the top of the page

后端 未结 3 638
广开言路
广开言路 2020-12-14 19:41

I found this, but this does it 100px before the bottom of the page. I need it 100px from the top of the page. I know how to implement it, I\'ve done other jquery animations,

相关标签:
3条回答
  • 2020-12-14 20:14

    Try this:

    var menu = $("nav");
    $(window).scroll(function(){
      //more then or equals to
      if($(window).scrollTop() >= 100 ){
           menu.show();
    
      //less then 100px from top
      } else {
         menu.hide();
    
      }
    });
    
    0 讨论(0)
  • 2020-12-14 20:17

    Try this:

    $(window).scroll(function() {
        if ($(window).scrollTop() > 100) {
            // > 100px from top - show div
        }
        else {
            // <= 100px from top - hide div
        }
    });
    
    0 讨论(0)
  • 2020-12-14 20:27

    I would recommend to do this:

    $("#divname").hide();
    $(window).scroll(function() {
        if ($(window).scrollTop() > 100) {
            $("#divname").fadeIn("slow");
        }
        else {
            $("#divname").fadeOut("fast");
        }
    });
    

    Now the div is already hidden when you visit your page.

    Without this:

    $("#divname").hide()
    

    It would show and then perform a FadeOut. And that is not what you want.

    0 讨论(0)
提交回复
热议问题