Javascript 当我向下滚动到孔div时,它将不再显示,如何淡出该div

Javascript 当我向下滚动到孔div时,它将不再显示,如何淡出该div,javascript,jquery,html,fadeout,slidedown,Javascript,Jquery,Html,Fadeout,Slidedown,我希望实现一个功能,在该功能中,通过按钮(或其他元素)单击页面顶部的slideDown显示通知,然后在滚动到视图之外时通过fadeOut隐藏通知。此功能类似于在上单击“如何工作”时发生的情况 为清楚起见,以下是我正在寻找的功能: 单击指定的元素以显示通知 通知滑入页面顶部的视图,窗口自动滚动到顶部 用户向下滚动页面,通知元素在滚动出视图后立即消失 有人知道如何实现这一点吗?很抱歉,代码太乱了,但它能让人明白这一点。 $(文档).ready(函数(){ $(“#slideDiv”)。单击(函数()

我希望实现一个功能,在该功能中,通过按钮(或其他元素)单击页面顶部的
slideDown
显示通知,然后在滚动到视图之外时通过
fadeOut
隐藏通知。此功能类似于在上单击“如何工作”时发生的情况

为清楚起见,以下是我正在寻找的功能:

  • 单击指定的元素以显示通知
  • 通知滑入页面顶部的视图,窗口自动滚动到顶部
  • 用户向下滚动页面,通知元素在滚动出视图后立即消失

  • 有人知道如何实现这一点吗?

    很抱歉,代码太乱了,但它能让人明白这一点。
    $(文档).ready(函数(){
    $(“#slideDiv”)。单击(函数(){
    $(“#banner”).show().animate({height:“300px”},0);
    });
    $(窗口)。滚动(功能(事件){
    var scroll=$(窗口).scrollTop();
    var link=$(“#横幅”);
    var offset=link.offset();
    var top=offset.top;
    var bottom=top+link.outerHeight();
    如果(滚动>底部){
    link.hide().css({height:0});
    滚动到(0,0);
    }
    });
    });
    
    #横幅{
    高度:0px;
    宽度:100%;
    显示:内联块;
    背景:#eee;
    过渡:高度0.5s;
    }
    
    Lorem ipsum dolor sit amet,是一位杰出的献身者。梅塞纳斯·布兰迪·萨皮恩·奎斯·奥古斯·布兰迪·福西布斯。这是一个很好的例子。梅塞纳斯·奎斯·迪亚姆·图皮斯。整型舌苔,枕叶,颞叶。nunc中的整数在mi bibendum bibendum中。这是我的工作。马克西姆斯、马蒂斯·坦普斯、图尔皮斯大变奏曲、莫里斯作品的非accumsan ex velit nec mauris。这是我的通心粉。Donec turpis ante,孕妇胎膜移植,semper nec dolor。
    梅塞纳斯在酒后驾车。大静脉曲张。但是,我的头发很长,舌苔很细,直径很小。艾蒂安ultrices magna Vita sagittis调味品。前庭大前庭前庭前庭前庭。大鼠多洛坐在阿米特·弗林利亚。在Elite enim,vulputate quis varius eu,egestas nec nulla。没有人影。毛里斯·福西布斯·泰卢斯在胡斯托港锡西登。前庭位于末梢。dapibus的无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾无尾。第二阶段是大项目。我们的宗教信仰,宗教信仰,宗教信仰。
    在比本杜姆马萨乌拉姆科珀的波尔蒂托·莫里斯·乌特·埃拉特·科莫多。Nunc设施是指孕妇的矢状体。努拉·埃吉特·奥古斯·森佩尔,利奥·ac·索利西图丁·托托。在mi tortor,porta ac libero pretium,mollis fringilla massa。梅塞纳斯拍卖商尼布·利古拉(nibh ligula),门静脉曲张。康莫多先生。奥古斯丁的埃尼安,非菲尼布斯·莫里斯。佩伦特斯克罗库斯·艾库利斯·利奥。tincidunt bibendum的Integer Pellentsque tellus。马来苏阿达河前的交通工具。努拉·波苏尔(NullaPosuere)的普雷森特(Praesent)、拍卖人里斯·塞德(risus sed)、帕特·利古拉(Pat ligula)。
    Nunc在欧盟法雷特拉之前举行了圣职仪式。奥古斯·亨德雷特、拉奥里特·埃拉特·维塔、马克西姆斯·马萨的努勒姆。多奈克猫咪,拉齐尼葡萄,孕妇,羊圈。第二阶段为第二阶段。在矢状体等分处的分子相思。别有用心。佩伦特斯的维塔酒,坐在阿梅特猫的调味品。在欧洲议会,欧洲议会,自由女神奥古斯·萨吉提斯·尼布,在卢克图斯·内克·图尔皮斯·艾尼姆(luctus neque turpis ac enim)。非调味品,非调味品。斜纹夜蛾悬钩子,斜纹夜蛾悬钩子,斜纹夜蛾悬钩子,斜纹夜蛾悬钩子,斜纹夜蛾悬钩子,斜纹夜蛾悬钩子。福斯·图皮斯·托托、斯克利斯·乌兰科佩尔·泰卢斯、艾库利斯·维韦拉·里苏斯。埃尼安·莫利斯·尼西葡萄品种,位于euismod tellus。整型乌兰科珀益普斯姆eget nisi rhoncus finibus。在交通事故发生前,请将货物交给我。这是一个封建的泰勒斯。在hac habitasse Plateum,一句名言。
    Nunc risus Elite,rutrum ac nisi in,孕妇前庭Nunc。在调味品nisi facilisis中,添加了两种苏打水blandit nisl。这是自由人民的自由,也是社会的自由。在索利西图丁,一辆车,一位智者,一位狮子座的老人。无主无主。我的生命是平等的,我的舌苔是痣,我的同侧皮肤是红色的。普鲁恩·乌兰科珀·马莱苏达·福西布斯。奈克·奎斯·尤里西斯的努克·莫莱斯蒂。Proin非直径非智人tristique viverra。
    这是一个很好的例子。在arcu PERLENTESQUE PORTAUT arcu的产前检查。这是一个很好的例子。在自然社会中,因怀孕而死亡的蒙特斯,因饥饿而死亡的蒙特斯,因饥饿而死亡的蒙特斯,因饥饿而死亡的蒙特斯,因饥饿而死亡的蒙特斯,因饥饿而死亡的蒙特斯,因饥饿而死亡的蒙特斯,因饥饿而死亡的蒙特斯,因饥饿而死亡的蒙特斯。不,我不知道该怎么办,我不知道该怎么办。非孕期酒后驾车者的特殊侵权行为。Aliquam Volatis Pat Aliquam felis,ac commodo felis venenatis nec。这是一个国际会议,它是一个共同的会议,在nibh的交通工具上举行会议。前庭不存在,这是一种名言。使用扫描电镜检查前庭的智者生命。
    佩伦特斯的维塔酒,坐在阿梅特猫的调味品。在欧洲议会,欧洲议会,自由女神奥古斯·萨吉提斯·尼布,在卢克图斯·内克·图尔皮斯·艾尼姆(luctus neque turpis ac enim)。非调味品,非调味品。斜纹夜蛾悬钩子,斜纹夜蛾悬钩子,斜纹夜蛾悬钩子,斜纹夜蛾悬钩子,斜纹夜蛾悬钩子,斜纹夜蛾悬钩子。福斯·图皮斯·托托、斯克利斯·乌兰科佩尔·泰卢斯、艾库利斯·维韦拉·里苏斯。埃尼安·莫利斯·尼西葡萄品种,位于euismod tellus。整型乌兰科珀益普斯姆eget nisi rhoncus finibus。在交通事故发生前,请将货物交给我。这是一个封建的泰勒斯。在里面
    
    $("#clickme").click(function() {
        $("#slideme").slideDown("slow");
    });
    
    $(document).scroll(function(){
        if($(document).scrollTop()>100 /* Insert height here */){
            $("#slideme").fadeOut();
        }
    });
    
    var $notification = $(".notification");
    
    $(document).on("click", ".show-button", function() {
        $notification.slideDown(); //can use whatever effect you want here, or just .show()
        window.scrollTo(0, 0); //scroll to top of page
    });
    
    $(window).on("scroll", function() {
        var notificationHeight = $notification.outerHeight(); //may be able to cache this or calculate outside the handler for reuse, depending on implementation
        var currentScrollY = $(window).scrollTop();
    
        if (currentScrollY > notificationHeight) {
            $notification.hide(); 
    
            //update the scroll browser scroll position
            var updatedScrollY = currentScrollY - notificationHeight;
            window.scrollTo(window.scrollX, updatedScrollY);
        }
    });
    
    $(window).on("scroll", function() {
        var notificationHeight = $notification.outerHeight(); //may be able to cache this or calculate outside the handler for reuse, depending on implementation
        var currentScrollY = $(window).scrollTop();
    
        if (currentScrollY > notificationHeight) {
            //can use whatever effect you want, but must pass scroll position update code in callback to prevent page jump, if not using .hide()
            $notification.fadeOut(function () {
              //update the scroll browser scroll position
              var updatedScrollY = currentScrollY - notificationHeight;
              window.scrollTo(window.scrollX, updatedScrollY);
            });
        }
    });
    
    //binds the scroll handler we created in step 2 to the window
    function bindScrollHandlerForNotification() {
        $(window).on("scroll.checkHideNotification", function() {
            var notificationHeight = $notification.outerHeight(); //may be able to cache this or calculate outside the handler for reuse, depending on implementation
            var currentScrollY = $(window).scrollTop();
    
            if (currentScrollY > notificationHeight) {
                //can use whatever effect you want, but must pass scroll position update code in callback to prevent page jump, if not using .hide()
                $notification.fadeOut(function() {
                    //update the scroll browser scroll position
                    var updatedScrollY = currentScrollY - notificationHeight;
                    window.scrollTo(window.scrollX, updatedScrollY);
    
                    //unbind the handler since the notification is hidden
                    $(window).off("scroll.checkHideNotification");
                });
            }
        });
    }
    
    $(document).on("click", ".show-button", function() {
        $notification.slideDown(); //can use whatever effect you want here, or just .show()
        window.scrollTo(0, 0); //scroll to top of page
        bindScrollHandlerForNotification();
    });