Jquery的每个循环上的marginTop与marginBottom

时间:2012-06-12 03:49:20

标签: jquery menu jquery-animate each sliding

嗨,大家好我已经基于jquery在我的网站上实现了一个movile固定菜单,但我在每个句子里面有一个marginTop和marginBottom的问题,marginBottom不工作它的接缝就像缺少的东西,plz检查出来

现场示例: http://www.utxj.edu.mx/menu_example/index.html

我的代码......

$(document).ready(function(){
    $(function() {
            var d=300;

            $('#navigation a').each(function(){
                $(this).stop().animate({
                    'marginTop':'-80px'
                },d+=150);
            });

            $('#navigation > li').hover(function () {
                $('a',$(this)).stop().animate({
                    'marginTop':'-2px'
                },200);
            }, function () {
                $('a',$(this)).stop().animate({
                    'marginTop':'-80px'
                },200);
            }
        );
    });
});

$(document).ready(function(){
    $(function() {
            var d=300;

            $('#navigation2 a').each(function(){
                $(this).stop().animate({
                    'marginBottom':'-80px'
                },d+=150);
            });

            $('#navigation2 > li').hover(function () {
                $('a',$(this)).stop().animate({
                    'marginBottom':'-2px'
                },200);
            }, function () {
                $('a',$(this)).stop().animate({
                    'marginBottom':'-80px'
                },200);
            }
        );
    });
});

Tnx 4帮助。

1 个答案:

答案 0 :(得分:1)

利润正在做他们应该做的事情。元素将增长以适应动画块的新大小,其余元素将随之拖动。

作为解决方案,请尝试将元素relative放置到当前位置,并为topbottom属性设置动画:

li {
  position: relative;
}