Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 粘性割台滑下效应_Jquery_Html_Css - Fatal编程技术网

Jquery 粘性割台滑下效应

Jquery 粘性割台滑下效应,jquery,html,css,Jquery,Html,Css,固定css $(window).scroll(function(){ var sticky = $('.top-menu'), scroll = $(window).scrollTop(); if (scroll >= 200){ sticky.addClass('fixed'); }else{ sticky.removeClass('fixed'); }

固定css

$(window).scroll(function(){
         var sticky = $('.top-menu'),
         scroll = $(window).scrollTop();

        if (scroll >= 200){
            sticky.addClass('fixed');
        }else{
            sticky.removeClass('fixed');
        }
    });
它工作得很好,但是我想要一个“顶部效果的向下滑动”,我可以这样做吗


谢谢

我对css的东西不太感兴趣,但我想这可能有用:

.fixed{
    position: fixed;
    background: red;
    z-index: 1;
}

我不太喜欢css的东西,但我想这可能会奏效:

.fixed{
    position: fixed;
    background: red;
    z-index: 1;
}

您应该研究CSS转换和转换属性

  • 过渡将控制对象设置动画的速度
  • 变换将控制对象的变换。(即从0到100px的高度)

学习CSS3的一个很好的资源是,您只需运行本教程。

您应该了解CSS转换和转换属性

  • 过渡将控制对象设置动画的速度
  • 变换将控制对象的变换。(即从0到100px的高度)

学习CSS3的一个很好的资源是,您只需运行本教程。

对于平滑的向下滑动动画,您可以尝试以下内容:
JS代码:

       if (scroll >= 200){
             sticky.slideDown();
            sticky.addClass('fixed');
        }else{

            sticky.slideUp();
            sticky.removeClass('fixed');
        }
CSS代码:

$(window).scroll(function(){
         var sticky = $('.top-menu'),
         scroll = $(window).scrollTop();
        if (scroll >= 200){
            sticky.addClass('fixed');
            sticky.slideDown(1000);
        }else{
            sticky.removeClass('fixed');
            sticky.removeAttr("style"); //slideDown adds the style="block" which needs to be removed so that next time slideDown will work
        }
    });

这里是逻辑;要在200px之后添加“固定”类,请滚动。此时,通过添加的CSS类,
sticky
display:none
。然后向下滑动,使其可见。如果用户向上滚动到200px以下,则删除
fixed
类并删除通过
slideDown()函数添加到
sticky
style
属性。希望这会有所帮助。我尝试过它,它的工作原理与

非常相似。对于平滑的向下滑动动画,您可以尝试以下方法:
JS代码:

       if (scroll >= 200){
             sticky.slideDown();
            sticky.addClass('fixed');
        }else{

            sticky.slideUp();
            sticky.removeClass('fixed');
        }
CSS代码:

$(window).scroll(function(){
         var sticky = $('.top-menu'),
         scroll = $(window).scrollTop();
        if (scroll >= 200){
            sticky.addClass('fixed');
            sticky.slideDown(1000);
        }else{
            sticky.removeClass('fixed');
            sticky.removeAttr("style"); //slideDown adds the style="block" which needs to be removed so that next time slideDown will work
        }
    });

这里是逻辑;要在200px之后添加“固定”类,请滚动。此时,通过添加的CSS类,
sticky
display:none
。然后向下滑动,使其可见。如果用户向上滚动到200px以下,则删除
fixed
类并删除通过
slideDown()函数添加到
sticky
style
属性。希望这会有所帮助。我试过了,它的工作原理与

非常相似。您可以尝试添加这样的代码,这样就不必指定像素高度:

.fixed{
    position: fixed;
    background: red;
    z-index: 1;
    display:none;
}

您可以尝试添加这样的代码,这样就不必指定像素高度:

.fixed{
    position: fixed;
    background: red;
    z-index: 1;
    display:none;
}

你能不能也发布相对的html?你能不能也发布相对的html?