1

我有一个 CSS 布局,如附图所示。 在此处输入图像描述
我想实现以下行为

  1. 当部分标题可见时,位置(滚动时)如图所示。
  2. 当 header 不可见时(我们向下滚动超过 header 长度),left、right 和 img 的位置应该是固定的,唯一可滚动的部分应该是页面内容。

到目前为止小提琴链接

Liam 建议了这个链接,但 javascript 有错误Uncaught TypeError: Property '$' of object [object DOMWindow] is not a function .也许它与 mootools 有关(我没有使用它)。如果没有 mootools,这个功能是否可行?

你能帮我看看这个定位风格吗?

谢谢你

4

2 回答 2

1

http://jsfiddle.net/juSvJ/ 这应该会有所帮助。

除非一个人的屏幕真的很小,否则无论如何它都应该工作。

于 2011-05-26T13:06:43.330 回答
1

测试了这个,工作正常

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript"
  src="https://ajax.googleapis.com/ajax/libs/mootools/1.3.2/mootools-yui-compressed.js">
</script>
<script type="text/javascript">
//<![CDATA[
window.onscroll = function()
{
    if( window.XMLHttpRequest ) {
        if (document.documentElement.scrollTop > 221 || self.pageYOffset > 221) {
            $('rightsidebar').style.position = 'fixed';
            $('rightsidebar').style.top = '0';
            $('leftsidebar').style.position = 'fixed';
            $('leftsidebar').style.top = '0';
        } else if (document.documentElement.scrollTop < 221 || self.pageYOffset < 221) {
            $('rightsidebar').style.position = 'absolute';
            $('rightsidebar').style.top = '221px';
            $('leftsidebar').style.position = 'absolute';
            $('leftsidebar').style.top = '221px';
        }
    }
}
//]]>
</script>
<style type="text/css">
/*<![CDATA[*/
body {margin:0;
}
#header {background:blue; height:221px;}
#rightsidebar {
        position:absolute;
        right: 0;
        top: 221px;
        width: 150px;
        color: #FFFFFF;
        background:red;
}

#leftsidebar {
        position:absolute;
        left: 0;
        top: 221px;
        width: 150px;
        color: #FFFFFF;
}
#topleft {background:green;}
#image {background:red;}
#footer {height:100px; background:yellow;}
/*]]>*/
</style>
<title></title>
</head>
<body>
<div id="header">header</div>
<div id="leftsidebar">
<div id="topleft">lkjlk</div>
<div id="image">IMAGE</div>
</div>
<div id="content"><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>
<div id="rightsidebar">lkjlk</div>
<div id="footer">Footer</div>
</body>
</html>
于 2011-05-26T21:13:00.150 回答