防止 jQuery 动画 div 宽度流畅移动内容

发布于 2024-10-18 11:20:24 字数 2931 浏览 6 评论 0原文

我有一个在页面加载时隐藏的 div,并通过 jQuery 拉伸到 100% 宽度。动画很棒,但内容会流畅地调整,直到它的容器(位于可拉伸的 div 内)达到其完整设置的宽度。

以前内容没有改变,我不知道在对代码进行多次编辑后是什么改变了这种行为!我怎样才能修复内容的移动;在没有任何移动的情况下显示调整大小的 div 允许的尽可能多的内容?具体问题是:

-#show_contact 锚点下降到它的两个姐妹下方,直到它有空间位于同一行上 -#collections div's margin:0 auto 受到#show_contact 短暂访问的影响

谢谢!

PS-这是它之前的样子/我希望它现在的样子: http://jsfiddle.net/ZP86m/

HTML:

<div id="slider">
    <div id="trigger">
        <img class="arrow_small" src="images/left_small.png" alt="slide menu out" />
    </div>
    <div class="trans" id="overlay"></div>
    <div id="content">
        <div id="main_nav">
            <div id="nav_links">
                <div class="nav_link"><h3><a class="showlink" id="show_campaigns" title="Campaigns">CAMPAIGNS</a></h3></div>
                <div class="nav_link"><h3><a class="showlink" id="show_collections" title="Collections">COLLECTIONS</a></h3></div>
                <div class="nav_link"><h3><a class="showlink" id="show_contact" title="Contact">CONTACT</a></h3></div>
        </div>
            <div id="nav_container">
                <div class="nav" id="campaigns">
                    <p>CAMPAIGNS!</p>
                </div>
                <div class="nav current" id="collections">
                    <p>COLLECTIONS!</p>
                </div>
                <div class="nav" id="contact">
                    <p>CONTACT!</p>
                </div>
            </div>
       </div>
    </div>
</div>

CSS:

    #slider {
    width:100%;
    height:100%;
    top:0;
    right:0;
    float:right;
    position:absolute;
}
#overlay {
    width:100%;
    height:100%;
    position:absolute;
}
#content {
    width:100%;
    height:100%;
    position:relative;
    z-index:1;
}
#main_nav {
    width:684px;
    height:100%;
    margin:0 auto;
    padding:0px 30px 0px 30px;
}
#nav_links {
    width:100%;
    height:40px;
}
.nav_link {
    width:33%;
    float:left;
    margin:20px 0px 0px 0px;
    position:relative;
    text-align:center;
}
.nav{
    width:208px;
    height:100%;
    padding:20px 10px 20px 10px;
    margin:0 auto;
    text-align:center;
}

JavaScript:

// Slide out menu
$('#slider')[0].style.width = '30px';
$(function() {
    $('#trigger').toggle(function (){
        $('#slider').animate({'width':'100%'}, 1500);
        $('.arrow_small').attr('src','images/right_small.png');
    }, function() {
        $('#slider').animate({'width':'30px'}, 1500);
        $('.arrow_small').attr('src','images/left_small.png');
    });
});

I've got a div that is hidden on page load and stretches to 100% width via jQuery. Animation is great, but the content fluidly adjust until it's container (which is within the stretchy div) reaches it's full set width.

Previously the content didn't shift and I can't tell what changed that behavior after so many edits to the code! How can I fix the content from moving; showing as much as the resizing div allows without any movement? The specific problems are:

-#show_contact anchor drops below its two sisters until it has room to be on the same line
-#collections div's margin:0 auto is affected by #show_contact's short visit

Thanks!

P.S.- here's what it looked like before/what I want it to look like now: http://jsfiddle.net/ZP86m/

HTML:

<div id="slider">
    <div id="trigger">
        <img class="arrow_small" src="images/left_small.png" alt="slide menu out" />
    </div>
    <div class="trans" id="overlay"></div>
    <div id="content">
        <div id="main_nav">
            <div id="nav_links">
                <div class="nav_link"><h3><a class="showlink" id="show_campaigns" title="Campaigns">CAMPAIGNS</a></h3></div>
                <div class="nav_link"><h3><a class="showlink" id="show_collections" title="Collections">COLLECTIONS</a></h3></div>
                <div class="nav_link"><h3><a class="showlink" id="show_contact" title="Contact">CONTACT</a></h3></div>
        </div>
            <div id="nav_container">
                <div class="nav" id="campaigns">
                    <p>CAMPAIGNS!</p>
                </div>
                <div class="nav current" id="collections">
                    <p>COLLECTIONS!</p>
                </div>
                <div class="nav" id="contact">
                    <p>CONTACT!</p>
                </div>
            </div>
       </div>
    </div>
</div>

CSS:

    #slider {
    width:100%;
    height:100%;
    top:0;
    right:0;
    float:right;
    position:absolute;
}
#overlay {
    width:100%;
    height:100%;
    position:absolute;
}
#content {
    width:100%;
    height:100%;
    position:relative;
    z-index:1;
}
#main_nav {
    width:684px;
    height:100%;
    margin:0 auto;
    padding:0px 30px 0px 30px;
}
#nav_links {
    width:100%;
    height:40px;
}
.nav_link {
    width:33%;
    float:left;
    margin:20px 0px 0px 0px;
    position:relative;
    text-align:center;
}
.nav{
    width:208px;
    height:100%;
    padding:20px 10px 20px 10px;
    margin:0 auto;
    text-align:center;
}

Javascript:

// Slide out menu
$('#slider')[0].style.width = '30px';
$(function() {
    $('#trigger').toggle(function (){
        $('#slider').animate({'width':'100%'}, 1500);
        $('.arrow_small').attr('src','images/right_small.png');
    }, function() {
        $('#slider').animate({'width':'30px'}, 1500);
        $('.arrow_small').attr('src','images/left_small.png');
    });
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林很绿却致人迷途 2024-10-25 11:20:24

main_nav 的填充必须与滑块动画的宽度相匹配

main_nav's padding had to match the width of the animation of slider

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文