简体   繁体   English

向下滚动其余100px时隐藏div

[英]hide the div when scroll down the remaining 100px

I want to hide my div , when scrolling down the remaining 100px. 向下滚动其余100px时,我想隐藏div If you have any answer please help me 如果您有任何答复,请帮助我

 $(document).scroll(function() { var y = $(this).scrollTop(); if (y > 2300) { $('.bottomMenu').show(); } else if { ? } else { $('.bottomMenu').hide(); } }); 
 .bottomMenu { display: none; position: fixed; top: 10%; width: 100%; height: 60px; border-top: 1px solid #000; background: red; z-index: 1; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="bottomMenu" style="background:red; height:100px;width:100px;">ikanbakar</div> 

This should be the code. 这应该是代码。 you should add a class in css as 您应该在CSS中添加一个类作为

bottomMenu.active{} bottomMenu.active {}

to define your styles there. 在那里定义您的样式。

$(window).on("scroll", function() {
    if($(window).scrollTop() > 2300) {
        $(".bottomMenu").addClass("active");
    } else {
       $(".bottomMenu").removeClass("active");
    }
});

well if you want this here is the example hope it can help you 好吧,如果您想要此示例,希望它可以为您提供帮助

 $(window).on("scroll", function() { if($(window).scrollTop() < 300) { //you have to change the value according to your content $(".bottomMenu").addClass("game"); } else { $(".bottomMenu").removeClass("game"); } }); 
 .bottomMenu{display:none;} .game { display:block; position: fixed; top: 10%; width: 100%; height: 60px; border-top: 1px solid #000; background: red;} .nav { font-weight: normal; list-style: none; text-align: center; width: 100%; top: 0; padding: 20px 0 20px 0; background-color: #4F4F4F; } .nav li { display: inline-block; padding: 0 25px 0 25px; } .nav li a { text-decoration: none; color: #ffffff; } .nav li a:hover { color: #c1c1c1; } .footer { float:left; list-style: none; text-align: center; position:relative; width: 100%; bottom: 0; padding: 20px 0 20px 0; } .footer li { display: inline-block; padding: 0 25px 0 25px; font-weight: lighter; } .footer li a { text-decoration: none; color: #ffffff; } header { display: inline-block; width: 100%; } .footer { background: #333; } body{ margin:0px auto;} 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <header> <ul class="nav"> <li><a href="index.html">HOME</a></li> <li><a href="projects.html">PROJECTS</a></li> <li><a href="about.html">ABOUT</a></li> </ul> </header> <section style="float:left;width:100%;"> <p> Ensure growth and profitability by extending our product portfolio in other categories of HPC business in domestic and international markets. Continuously improve our system and products to enhance customer satisfaction. Continue with our commitment to operate business in an ethical manner. Develop & motivate ZIL people to build a high performance culture. Deliver high quality branded and innovative products and services to ensure customer satisfaction. Simplify business processes and reduce complexity to achieve business growth. Optimize resources to ensure competitiveness. Ensure regulatory and statutory compliance and embed best practices of corporate governance.</p> <div class="bottomMenu game" style="background:red; height:100px;width:100px;">ikanbakar</div> <p> Ensure growth and profitability by extending our product portfolio in other categories of HPC business in domestic and international markets. Continuously improve our system and products to enhance customer satisfaction. Continue with our commitment to operate business in an ethical manner. Develop & motivate ZIL people to build a high performance culture. Deliver high quality branded and innovative products and services to ensure customer satisfaction. Simplify business processes and reduce complexity to achieve business growth. Optimize resources to ensure competitiveness. Ensure regulatory and statutory compliance and embed best practices of corporate governance.</p> </section> <footer> <ul class="footer"> <li><a href="https://steamcommunity.com/id/wow">Made by Lumo © 2017</a> </li> </ul> </footer> 

can you try this ? 你可以试试吗?

$(document).scroll(function () {
    if(($(document).height() - $(document).scrollTop()) > 100 ) {
       $('.bottomMenu').show();
    } else {
       $('.bottomMenu').hide();
    }
});

or javascript way like 或javascript方式

document.documentElement.scrollHeight - document.documentElement.scrollTop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM