Animate函数设置以像素为单位的宽度,而不是百分比给定值时的百分比

时间:2014-03-14 18:59:19

标签: javascript jquery html

我正在尝试使用jQuery的animate函数来使用此代码增加元素的宽度:

$('.center-left').animate({width:'50%'});

但它将div的值设置为50px

添加HTML代码

    <!Doctype HTML>
<html>
    <head>
        <link rel='stylesheet' type='text/css' href='style.css'>
        <script src='jquery-1.7.js'></script>
        <script type='text/javascript' src='script.js'></script>
    </head>
    <body>
        <div class='header'>        
            <ul id='nav'>
                <li class='nav-2'><a href='#'>HOME</a></li>
                <li class='nav-1'><a href='#'>INFO</a> </li>
                <li class='nav-2'><a href='#'>COMPANY</a></li>
                <li class='nav-1'><a href='#'>CONTACTS</a></li>
                <li class='nav-2'><a href='#'>CLIENTS</a></li>
                <div style="clear:both"></div>
            </ul>

        </div>
        <div class='center'>
            <div id='center-left'>
                <div id='left-top'>
                    <span id='c'>
                        C
                    </span>
                    <span id='o'>
                        O
                    </span>
                    <span id='n'>
                        N
                    </span>
                </div>
                <div id='left-bottom'>
                    <span id='t'>
                        T
                    </span>
                    <span id='a'>
                        A
                    </span>
                    <span id='C'>
                        C
                    </span>
                    <span id='t'>
                        T
                    </span>
                </div>
            </div>
            <div id='center-right'>
            </div>
        </div>
        <div class='footer'>
            <span id='copyright'> Copyright &copy; 2010. All Rights Reserved</span>   
        </div>

    </body>

</html>

我正在尝试代码

$(document).ready(function(){$('#center-left').animate({width:'50%'});

最初我将宽度设置为0

添加css

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}
@font-face{
font-family:chaletlondon;
src:url('fonts/chalet-londonnineteenseventy.woff');
}
ul{

font-family:chaletlondon;
}
li{
display:inline-block;
float:left;
padding-left:150px;
}
a{
text-decoration:none;
color:black;
}
.header{
width:100%;
border:1px solid black;
height:100px;
}
#nav{
border:1px solid black;
height:100px;
width:100%;
display:inline-block;
margin:0px;
position:relative;
top:0%
}
.footer{
position:relative;
margin-left:auto;
margin-right:auto;
width:50%;
text-align:center;
bottom:0;
border:1px solid;
height:90px;
}
.center{
height:470px;
border:1px solid ;
margin:0;
bottom:3%;
width:100%;
}
#copyright{
display:inline-block;
position:relative;
top:80%;
border:1px solid ;
}
.nav-1,.nav-2{
position:relative;
bottom:10%;
opacity:0;
}
#center-left{
background-color:black;
height:100%;
width:0;
}
#left-top,#left-bottom{
height:50%;
border:1px solid white;
}
#c,#o,#n{
color:white;
width:32%;
height:100%;
font-size:343px;
display:inline-block;
border:1px solid white;
line-height:72%;
}
#C,#t,#a{
color:white;
width:24%;
height:100%;
font-size:332px;
display:inline-block;
border:1px solid white;
line-height:71%;
}

我找到了http://bugs.jquery.com/ticket/10669

的解决方案

它是jquery-1.7中的一个错误,它不支持动画宽度百分比..!它在版本1.6中受支持,但在包含1.6 jquery之后,代码工作正常!

0 个答案:

没有答案