如何让div在2个高度之间出现和消失? [英] How to make a div appear and disappear between 2 heights?

查看:113
本文介绍了如何让div在2个高度之间出现和消失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里获得了一些Javascript,这使得div在页面的某个高度出现,但是我想让它在另一个高度再次消失,因此它在一系列像素之间显示。例如,我希望div出现在500的高度,并在700处再次消失。

I have got a bit of Javascript here which makes a div appear at a certain height on the page however I want to make it disappear again at another height so it displays between a range of pixels. E.g I want the div to appear at a height of 500 and disappear again at 700.

以下是我的代码:

Here is the following code I have:

<script type="text/javascript">
    $(document).ready(function(){
        $("#testdiv").hide();
        $(window).scroll(function(){
              if($(window).scrollTop()>500){
                 $("#testdiv").fadeIn();
              }else{
                 $("#testdiv").fadeOut();
              }
        });
    });
</script>

感谢您的帮助,
瑞恩。

Would appreciate the help, Ryan.

推荐答案

这是否工作?我添加了一个额外的检查来查看scrollTop是否高于700.如果是,隐藏 #testdiv

Does this work? I added an additional check to see if the scrollTop is higher than 700. If so, hide the #testdiv

<script type="text/javascript">
    $(document).ready(function(){
        $("#testdiv").hide();
        $(window).scroll(function(){
              if($(window).scrollTop()>500){
                 if($(window).scrollTop()>700){
                    $("#testdiv").fadeOut();
                 }
                 else
                 {
                    $("#testdiv").fadeIn();
                 }
              }
        });
    });
</script>

这篇关于如何让div在2个高度之间出现和消失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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