简体   繁体   中英

div slid down from top of page to center using jquery

i need to slide down a div from top of page to center. i tried(pleas check the code) but it is sliding from button to down.what i need is ,when i click button , one div slide from top of the page to center.when i click the close button , it should close the div. please give me some suggestion or ref link.

<div id="divtbl" >
<table style="width:100%">
    <tr>
        <td>
            Table Names
        </td>

    </tr>
    <tr>
        <td>
            Table Names 1
        </td>

    </tr>
   <tr>
        <td>
            <input type="button" value="Add New Feild" onclick="addnewrow()" />
        </td>

    </tr>
</table>
    </div>
<div id="divpopup" style="display:none;"  class="pop">
    <table style="width:100%">
    <tr>
        <td>
            display Names
        </td>

    </tr>
    <tr>
        <td>
            display Names 1
        </td>

    </tr>
    <tr>
        <td>
            display Names 2
        </td>

    </tr>

</table>
</div>


<style type="text/css">
    .pop
    {
        font-size:12px;
        top:0px;
        position:absolute;    
    }
</style>
 <script type="text/javascript">
    function addnewrow() {
        try
        {
            $("#divpopup").slideToggle("slow");
        }
        catch (e) {
            alert(e.message);
        }
    }
   </script>

Try this to position your popup div at center of the page-

.pop
{
    font-size:12px;
    top:40%;
    left:40%;
    position:absolute;    
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM