Use jquery to make div appear after a user scrolls

那年仲夏 提交于 2019-11-29 10:24:42

问题


I'd like to have a div appear after a user scrolls down on a page, and disappears if they scroll back to the top.

I thought using the .scroll() function in jquery would be useful, but couldn't quite figure out how to make this happen.

Any help would be appreciated. Thanks!


回答1:


Something like this should do the trick:

$(window).scroll(function() {
    if ($(this).scrollTop() == 0) {
        $("#mydiv:visible").hide();
    }
    else {
        $("#mydiv:hidden").show();
    }
});


来源:https://stackoverflow.com/questions/4573767/use-jquery-to-make-div-appear-after-a-user-scrolls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!