<!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=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(function(){
$("#div_float_right").bind("click",function(){
if($("#div_float_left").css("display")=="block"){
$("#div_float_left").css("display","none");
}else if($("#div_float_left").css("display","none")){
$("#div_float_left").css("display","block");
}
});
$("#div_float").css("top",0);
$("#div_float").css("left",$(window).width()-200); //右上边
$("#div_float").css("left",0); //左上边
//左下边
$("#div_float").css("top",$(window).height()-420); //420等层自身的高度
$("#div_float").css("left",$(window).width()-200); //右下边 //200等层自身的宽度 $("#div_float").css("top",$(window).height()-402);
$(window).bind("scroll",function(){
var p=$(this);
var d=$(document);
// $("#div_float").css("top",p.scrollTop()+110);
// $("#div_float").css("left",p.scrollLeft()+10);
// alert(d.scrollTop());
});
});
</script>
</head>
<body>
<div id="div_float" style="width:200px; height:400px; border:1px solid #ff0000; line-height:400px; vertical-align:middle; position:fixed; left:px; top:0px; ">
<div id="div_float_left" style="width:150px; height:300px; border:1px solid #cc66e8; float:left; margin: auto auto;">
</div>
<div id="div_float_right" style="width:30px; border:1px solid #99bbe8; height:300px; float:left; cursor:pointer"></div>
</div>
<div style="width:1500px; height:1500px; border:1px solid #ccee68"></div>
</body>
</html>
//也就是用窗体的高度或宽度-层自身的高度或宽度附值给层的left,top,再把层的position:fixed就可以了
必须有这句话:
<!DOCTYPE html > 或者<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
才能固定位置;如果还想要100%有用,就用前面那句,既能百分百又能固定