我有一个CSS布局,如附图所示。
我想实现以下行为
答案 0 :(得分:1)
http://jsfiddle.net/juSvJ/ 应该有所帮助。
除非一个人的屏幕非常小,否则无论如何都应该有效。
答案 1 :(得分: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>