jQuery 动画水平拉伸左侧问题

发布于 2024-10-17 21:44:57 字数 3895 浏览 7 评论 0原文

我正在尝试将与页面右侧对齐的 div 从页面宽度的 30 像素拉伸到页面宽度的 100%。我的 javascript 在页面上移动 30px 条..错误:(

谢谢!

HTML:

 <div id="header">
    <div id="logo">
                <h1>DEETRA</h1>
            </div>
</div>
<div id="main">
            <div id="trigger_left">
                <img class="arrow_small" id="main_arrow" src="images/left_small.png" alt="slide menu out" />
        </div>
            <div id="trigger_right">
                <img class="arrow_small" id="main_arrow" src="images/right_small.png" alt="slide menu in" />
            </div>
            <div id="slider">
                <div class="trans" id="overlay"></div>
                <div id="content">
                    <div id="main_nav">
                <div class="nav" style="float:left;">
                                <h3>CAMPAIGNS</h3>
                                <p>Sed enim risus, congue non, tristique in, commodo eu, metus.</p>
                        </div>
                            <div class="nav" style="float:right;">
                                <h3>CONTACT</h3>
                                <p>Sed enim risus, congue non, tristique in, commodo eu, metus.</p>
                        </div>
                            <div class="nav" style="margin:0 auto;">
                             <h3>COLLECTIONS</h3>
                             <p>Sed enim risus, congue non, tristique in, commodo eu, metus.</p>
                        </div>
                       </div>
            </div>
            </div>
 </div>

CSS:

* {
margin:0;
}
body {
    width:100%;
    height:100%;
    background:url(../images/one.jpg) no-repeat;
    background-size:100%;
    padding:0px;
    font-family:FuturaStdLight, Futura, Helvetica, Arial, sans-serif;
    font-size:14px;
    color:#fff;
    line-height:120%;
}
.trans {
    background-color:#000;
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";
    filter:alpha(opacity=70);
    -moz-opacity:0.70;
    -khtml-opacity:0.70;
    opacity:0.70;
}
#logo {
    width:213px;
    height:105px;
    position:relative;
    background:url(../images/logo.png) no-repeat 0 0;
    white-space:nowrap;
    text-indent:9999px;
    overflow:hidden;
}
#main {
    width:100%;
    height:306px;
    top:50%;
    margin-top:-153px;
    position:absolute;
    overflow: hidden;
}
#trigger_left {
    width:30px;
    height:100%;
    float:right;
    position:relative;
    z-index:2;
}
#trigger_right {
    width:30px;
    height:100%;
    float:left;
    position:relative;
    z-index:2;
}
.arrow_small {
    left:50%;
    top:50%;
    margin-left:-6px;
    margin-top:-12px;
    position:absolute;
}
#slider {
    width:inherit;
    height:inherit;
    top:0;
    right:0;
    float:right;
    position:absolute;
}
#overlay {
    width:inherit;
    height:inherit;
    position:absolute;
}
#content {
    width:inherit;
    height:inherit;
    position:relative;
    z-index:1;
}
#main_nav {
    width:744px;
    margin:0 auto;
    padding:0px 30px 0px 30px;
}
.nav{
    width:208px;
    padding:20px 10px 20px 10px;
    text-align:center;
}
#footer {
    height:12px;
    position:absolute;
    bottom:0;
    right:0;
    padding:0px 40px 40px 0px;
    z-index:1;
}

Javascript:

$(document).ready(function(){
// Hide functions
    $('#slider').css({width: '30px'});
// Navigation drop down menu
    $('#trigger_left').click(function (){
        $('#slider').animate({ width: '100%' }, 1500 );
    });
    $('#trigger_right').click(function (){
        $('#slider').animate({ width: '30px',}, 1500 );
    });     
});

I'm trying to stretch a div aligned to the right side of the page from 30px to 100% of page width. My javascript is moving a 30px bar across the page.. wrong :(

Thank you!

HTML:

 <div id="header">
    <div id="logo">
                <h1>DEETRA</h1>
            </div>
</div>
<div id="main">
            <div id="trigger_left">
                <img class="arrow_small" id="main_arrow" src="images/left_small.png" alt="slide menu out" />
        </div>
            <div id="trigger_right">
                <img class="arrow_small" id="main_arrow" src="images/right_small.png" alt="slide menu in" />
            </div>
            <div id="slider">
                <div class="trans" id="overlay"></div>
                <div id="content">
                    <div id="main_nav">
                <div class="nav" style="float:left;">
                                <h3>CAMPAIGNS</h3>
                                <p>Sed enim risus, congue non, tristique in, commodo eu, metus.</p>
                        </div>
                            <div class="nav" style="float:right;">
                                <h3>CONTACT</h3>
                                <p>Sed enim risus, congue non, tristique in, commodo eu, metus.</p>
                        </div>
                            <div class="nav" style="margin:0 auto;">
                             <h3>COLLECTIONS</h3>
                             <p>Sed enim risus, congue non, tristique in, commodo eu, metus.</p>
                        </div>
                       </div>
            </div>
            </div>
 </div>

CSS:

* {
margin:0;
}
body {
    width:100%;
    height:100%;
    background:url(../images/one.jpg) no-repeat;
    background-size:100%;
    padding:0px;
    font-family:FuturaStdLight, Futura, Helvetica, Arial, sans-serif;
    font-size:14px;
    color:#fff;
    line-height:120%;
}
.trans {
    background-color:#000;
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";
    filter:alpha(opacity=70);
    -moz-opacity:0.70;
    -khtml-opacity:0.70;
    opacity:0.70;
}
#logo {
    width:213px;
    height:105px;
    position:relative;
    background:url(../images/logo.png) no-repeat 0 0;
    white-space:nowrap;
    text-indent:9999px;
    overflow:hidden;
}
#main {
    width:100%;
    height:306px;
    top:50%;
    margin-top:-153px;
    position:absolute;
    overflow: hidden;
}
#trigger_left {
    width:30px;
    height:100%;
    float:right;
    position:relative;
    z-index:2;
}
#trigger_right {
    width:30px;
    height:100%;
    float:left;
    position:relative;
    z-index:2;
}
.arrow_small {
    left:50%;
    top:50%;
    margin-left:-6px;
    margin-top:-12px;
    position:absolute;
}
#slider {
    width:inherit;
    height:inherit;
    top:0;
    right:0;
    float:right;
    position:absolute;
}
#overlay {
    width:inherit;
    height:inherit;
    position:absolute;
}
#content {
    width:inherit;
    height:inherit;
    position:relative;
    z-index:1;
}
#main_nav {
    width:744px;
    margin:0 auto;
    padding:0px 30px 0px 30px;
}
.nav{
    width:208px;
    padding:20px 10px 20px 10px;
    text-align:center;
}
#footer {
    height:12px;
    position:absolute;
    bottom:0;
    right:0;
    padding:0px 40px 40px 0px;
    z-index:1;
}

Javascript:

$(document).ready(function(){
// Hide functions
    $('#slider').css({width: '30px'});
// Navigation drop down menu
    $('#trigger_left').click(function (){
        $('#slider').animate({ width: '100%' }, 1500 );
    });
    $('#trigger_right').click(function (){
        $('#slider').animate({ width: '30px',}, 1500 );
    });     
});

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

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

发布评论

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

评论(2

人疚 2024-10-24 21:44:57

丹尼尔,我将你的问题放入 jsfiddle,将图像更改为蓝色 div,并在你的 #slider 周围添加边框,这样我就可以看到它在做什么。

如果我正确理解你的问题,你的代码就会完全按照你想要的方式去做。看看:http://jsfiddle.net/nn4sJ/3/

Daniel, I put your question into a jsfiddle, changed the images to blue divs, and put a border around your #slider so I could see what it was doing.

if I understand your question correctly, your code does exactly what you want it to. Check it out: http://jsfiddle.net/nn4sJ/3/

软甜啾 2024-10-24 21:44:57

修改了一些CSS,现在可以了。使用 width:100% 而不是继承。

#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;
}

Changed some css, now it works. Used width:100% instead of inherited.

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