从顶部向下滚动100像素时,如何使div消失? [英] How can I make a div disappear when scrolling down 100px from the top?

查看:123
本文介绍了从顶部向下滚动100像素时,如何使div消失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我向下滚动100px时,我想使一个div消失,然后从浏览器窗口的顶部再次出现在该100px之内时,重新出现.我不希望任何动画只希望它消失并重新出现.可以仅使用HTML和CSS来完成此操作吗?有人可以给我提供此代码吗?

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 want it to vanish and reappear. Can this be done in just HTML and CSS? Can someone provide me the code for this please?

谢谢,马特

推荐答案

您将无法使用纯HTML或CSS进行此操作,您将需要使用Javascript,最好的选择是jQuery-这样使用以下命令相对容易做到这一点:

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();
     }
});

这篇关于从顶部向下滚动100像素时,如何使div消失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆