js控制div 在页面的固定位置

<script type=text/javascript>

window.onresize = resizeDiv;
        window.onscroll = resizeDiv;
        function resizeDiv()
        {
            var docWidth = document.documentElement.clientWidth;
            var docHeight = document.documentElement.clientHeight;
            document.getElementById("branding").style.top = parseInt(document.documentElement.scrollTop,10)+70;
            document.getElementById("branding").style.left = parseInt(document.documentElement.scrollLeft,10)+300;
        }</script>

然后body中的div :

<div id="branding" style="position:absolute; visibility:visible; left:300px; top:50px; z-index:2">
<asp:TextBox ID="TextName" runat="server"></asp:TextBox>
    <asp:Button ID="BtnAdd" runat="server" OnClientClick="return validateChecked()" onclick="BtnAdd_Click" Text="添加" />
    <asp:Button ID="BtnEdit" runat="server" OnClientClick="return validateChecked()" onclick="BtnEdit_Click" Text="修改" />
    <asp:Button ID="BtnDel" runat="server" OnClientClick="return validateChecked()" onclick="BtnDel_Click" Text="删除" />  
</div>

你可能感兴趣的:(div)