javascript - jQuery slidedown menu on scroll - Stack Overflow

How can i have a smooth slide down jQuery when I scroll down the page?Like on this page:I am using this

How can i have a smooth slide down jQuery when I scroll down the page?

Like on this page:

I am using this code, it works but it's not smooth, it's not sliding down, it just appears with no effect:

var bar = $('div.navbar');
    var top = bar.css('top');
    $(window).scroll(function() {
        if($(this).scrollTop() > 100) {
            bar.stop().addClass('navbar-fixed-top').animate({'top' : '0px'}, 500);
        } else {
            bar.stop().removeClass('navbar-fixed-top').animate({'top' : top}, 500);
        }
    });

How can i have a smooth slide down jQuery when I scroll down the page?

Like on this page: https://www.behance/gallery/8571121/JobEngine-WordPress-Theme-By-Engine-Themes

I am using this code, it works but it's not smooth, it's not sliding down, it just appears with no effect:

var bar = $('div.navbar');
    var top = bar.css('top');
    $(window).scroll(function() {
        if($(this).scrollTop() > 100) {
            bar.stop().addClass('navbar-fixed-top').animate({'top' : '0px'}, 500);
        } else {
            bar.stop().removeClass('navbar-fixed-top').animate({'top' : top}, 500);
        }
    });
Share Improve this question asked Jun 11, 2014 at 10:54 Augusto TristeAugusto Triste 4617 silver badges8 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 4

try to set the top value negative and animate it to 0px.

bar.stop().addClass('navbar-fixed-top').css('top','-50px').animate({'top' : '0px'}, 500);

watch my fiddle: http://jsfiddle/mjGRr/

One way of Acplishing this is by first keeping the height of the element 0px and then increasing the height as required.

check this fiddle :http://jsfiddle/FuH2p/ - I have done the same effect using css. I guess you have wont be having any trouble converting it to javascript!!!

HTML

<div class="outer">
    <div class="inner">
        <div>
</div>

CSS

.outer{
    widht:100%;
    height:300px;
    background:#ddd;
    border:5px solid #343434;
}

.inner{
    position:relative;
    top:0px;
    width:100%;
    height:0px;
    background:green;
    -webkit-transition:all .4s ease-in-out;
}

.outer:hover > .inner{
    height:30px;
}

OR here you go ( something like this)

keep a duplicate nav bar fixed on top with height 0px;

.duplicateNavbar{
   display:fixed;
   top:0px;
   height:0px;
}

    $(window).scroll(function() {
        if($(this).scrollTop() > 100) {
            $('.duplicateNavbar').animate({'height' : '56px'}, 500);
        } else {
            $('.duplicateNavbar').animate({'height' : '0px'}, 500);
        }
    });

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745560407a4633074.html

相关推荐

  • javascript - jQuery slidedown menu on scroll - Stack Overflow

    How can i have a smooth slide down jQuery when I scroll down the page?Like on this page:I am using this

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信