首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jquery的each循环上的marginTop与marginBottom

Jquery的each循环上的marginTop与marginBottom
EN

Stack Overflow用户
提问于 2012-06-12 11:49:20
回答 1查看 2.8K关注 0票数 0

大家好,我已经在我的网站上实现了一个基于jquery的移动固定菜单,但我在每个句子中的marginTop和marginBottom有一点问题,marginBottom不工作它看起来像是缺少了什么,请检查一下。

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

我的代码...

代码语言:javascript
复制
$(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救命

EN

回答 1

Stack Overflow用户

发布于 2012-06-12 11:54:12

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

作为一种解决方案,可以尝试将元素relative定位到其当前位置,并设置其topbottom属性的动画:

代码语言:javascript
复制
li {
  position: relative;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10990315

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档