日期:2014-05-17  浏览次数:20500 次

如何让顶层DIV始终显示,不随滚动条而滚动
如图吧,表达不清了...

就是让toobar始终显示,不出现在下来滚动条内。不要再用frameset了。
toobar中用的是telerik的一套控件,对这套控件不熟悉,里面有没有自带的这样一个控件?
toobar层代码:
C# code
<telerik:radtoolbar id="RadToolBar1" runat="server" onclientbuttonclicked="ToolBarClick"
            width="100%" onbuttonclick="RadToolBar1_ButtonClick">
            <Items>
                <telerik:RadToolBarButton Text="新增" Value="Add" ImageUrl="~/images/icon/Add.gif"
                    PostBack="false">
                </telerik:RadToolBarButton>
                <telerik:RadToolBarButton Text="查询" Value="Search" ImageUrl="~/images/icon/Search.gif">
                </telerik:RadToolBarButton>
            </Items>
        </telerik:radtoolbar>



------解决方案--------------------
找一下css的position属性,用fixed
可能会有浏览器兼容的问题
------解决方案--------------------
CSS code

right:0px;top:180px;position:fixed;_position:absolute;_bottom:auto;_margin-top:180px;_top:expression(eval(document.documentElement.scrollTop));

------解决方案--------------------
HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>浮动效果</title>
</head>
<body>
<div id="Ad" style="position:relative; width:300px; left:10px; top:50px;height:600px;background-color:red; line-height:70">Text</div>

<script type="text/javascript">
    function FloatDiv(id) {
        this.ID = id;
        this.ObjMove = document.getElementById(id);
        this.LastScrollY = 0; // 已经移动
        FloatDiv.prototype.Move = function(obj) {
            var scrollTop;
            if (document.documentElement && document.documentElement.scrollTop)
                scrollTop = document.documentElement.scrollTop;
            else if (document.body)
                scrollTop = document.body.scrollTop;
            var percent; // 本次移动像素
            percent = (scrollTop - obj.LastScrollY) * 0.1; // 每次移动10%
            if (percent > 0) percent = Math.ceil(percent); // 截掉小数,数字会变大
            else percent = Math.floor(percent); // 截掉小数,数字会变小
            obj.ObjMove.style.top = parseInt(obj.ObjMove.style.top) + percent + 'px';
            obj.LastScrollY = obj.LastScrollY + percent;
        };
        FloatDiv.prototype.Init = function(obj) {
            if (!obj.ObjMove) {
                alert('对象不存在');
                return;
            }
            window.setInterval(this.BindInterval(this.Move, obj), 10);
        };
        // 绑定参数,window.setInterval,不能指定参数,需要绑定
        FloatDiv.prototype.BindInterval = function(funcName) {
            var args = [];
            for (var i = 1; i < arguments.length; i++) {
                args.push(arguments[i]);
            }
            return function() { funcName.apply(this, args); }
        };
    }
    // 使用方法
    // <div id="Ad" style="position:relative;height:600px;background-color:red">Text</div>
    var ad = new FloatDiv('Ad');
    ad.Init(ad);
</script> 
</body>
</html>

------解决方案--------------------
HTML code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml