最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JQuery animate with slidedown - Stack Overflow

programmeradmin6浏览0评论

My top nav has an animation. While scrolling down it works fine, but the animation es with fade effect. What i want is slidedown effect of the background. As scroll doesn't trigger the slide down, Cant make it work like sliding down. can anyone help me?

here is my site:

and here is my code:

$(function() {
var floating_navigation_offset_top = $('#floating-nav').offset().top;
$(window).scroll(function(){
    var scrollTop = $(window).scrollTop();
    if(scrollTop > floating_navigation_offset_top)
        $('#floating-nav').stop().animate({'opacity':'1'},800).css({'position':'fixed','top': '0', 'z-index': '99'});
    else   
        $('#floating-nav').stop().animate({'opacity':'0'},40);
});

});

My top nav has an animation. While scrolling down it works fine, but the animation es with fade effect. What i want is slidedown effect of the background. As scroll doesn't trigger the slide down, Cant make it work like sliding down. can anyone help me?

here is my site:

http://goo.gl/8xt1XZ

and here is my code:

$(function() {
var floating_navigation_offset_top = $('#floating-nav').offset().top;
$(window).scroll(function(){
    var scrollTop = $(window).scrollTop();
    if(scrollTop > floating_navigation_offset_top)
        $('#floating-nav').stop().animate({'opacity':'1'},800).css({'position':'fixed','top': '0', 'z-index': '99'});
    else   
        $('#floating-nav').stop().animate({'opacity':'0'},40);
});

});
Share Improve this question edited Mar 8, 2014 at 16:21 T J 43.2k13 gold badges86 silver badges142 bronze badges asked Mar 8, 2014 at 15:49 Samia RupontiSamia Ruponti 4,05813 gold badges47 silver badges63 bronze badges 2
  • "but as scroll don't trigger the slide down" What do you mean? – A. Wolff Commented Mar 8, 2014 at 15:53
  • Please check the site. I meant when i scroll the slideDown() is not working there. only i found animate() working. – Samia Ruponti Commented Mar 8, 2014 at 15:55
Add a ment  | 

1 Answer 1

Reset to default 4

From what I understand, if you want a slide down effect, instead of animating opacity, simply animate the height from 0 to the height of your slide down menu.

update:

Even better, as per Alexander Lozada's ment, you can use .slideDown() function.

$(selector).slideDown(speed,callback);

further update: as requested, here's a simple fiddle

note: for slideDown to work, element should be hidden by JQ methods such as slideUp(), or css display:none etc

发布评论

评论列表(0)

  1. 暂无评论