代码之家  ›  专栏  ›  技术社区  ›  yl2201

Jquery动画未在指定为%

  •  0
  • yl2201  · 技术社区  · 6 年前

    一般来说,我对javascript和javascript动画属性很陌生,请帮助我。我希望图像填充整个身体的宽度50%-->100% . 当我把鼠标悬停在它上面时,我希望它变为100%。

    更多文字导致stackoverflow需要更多

    HTML:

    <html lang="en">
    <head>
    <script type="text/javascript" src ="js/a.js"></script>
    <link rel="stylesheet" href="css/a.css" type="text/css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    </head>
    <body>
    <div class="content">
        <div class="col-1" id="column1">
            <div class="col-1c" id="column1c">
                <img src="images/ngnl.jpg" onmouseover="colmover1()">
            </div>
        </div>
    </div>
    </body>
    </html>
    

    CSS:

    .content{
    background:rgba(0,0,0,0.5);
    z-index:0;
    position:relative;
    }
    .col-1{
    position:relative;
    float:left;
    width:50%;
    height:100%;
    background-image:url('../images/ngnlfull.jpg'); 
    background-repeat:no-repeat;
    background-size: cover;
    }
    .col-1c{
    background-color: rgba(0, 0, 0, 0.7);
    float:left;
    width: 100%;
    height: 100%;
    }
    .col-1c img{
    display:block;
    margin:auto;
    max-width:100%;
    height:50%;
    border-radius:50%;
    margin-top:25%;
    }
    body{
    margin: 0px;
    padding: 0px; 
    outline: none;
    border: 0px;
    background-image: url('../images/bg.jpg');
    background-repeat: no-repeat;
    background-attachment: fixed;
    }
    

    Javascript:

    function colmover1(){
        var column1 = document.getElementById("column1");
        var column1c = document.getElementById("column1c");
        var column2 = document.getElementById("column2");
        var column2c = document.getElementById("column2c");
    
        column1.animate({width:'100%'});
    }
    
    1 回复  |  直到 4 年前
        1
  •  0
  •   marc_s    4 年前

    // used css
    .content{
    background:rgba(0,0,0,0.5);
    z-index:0;
    position:relative;
    }
    .col-1{
    position:relative;
    float:left;
      width:50%;
      transition: width 0.5s;
    height:100%;
    background-image:url('../images/ngnlfull.jpg'); 
    background-repeat:no-repeat;
    background-size: cover;
    }
    
    .col-1:hover{
    width:100%;
    }
    .col-1c{
    background-color: rgba(0, 0, 0, 0.7);
    float:left;
    width: 100%;
    height: 100%;
    }
    .col-1c img{
    display:block;
    margin:auto;
    width:100%;
    border-radius:50%;
    margin-top:25%;
    }
    body{
    margin: 0px;
    padding: 0px; 
    outline: none;
    border: 0px;
    background-image: url('../images/bg.jpg');
    background-repeat: no-repeat;
    background-attachment: fixed;
    }
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <script type="text/javascript" src ="js/a.js"></script>
    <link rel="stylesheet" href="css/a.css" type="text/css">
    </head>
    <body>
    <div class="content">
        <div class="col-1" id="column1">
            <div class="col-1c" id="column1c">
                <img src="https://i.stack.imgur.com/zcdbj.jpg?s=48&g=1" onmouseover="colmover1()">
            </div>
        </div>
    </div>
    </body>
    </html>