你的位置:齐鲁公社 >> 科教 >> 电脑网络 >> 网页设计 >> 详细内容 在线投稿

js让一行页脚始终保持在底部

99书城会员招募      特惠酒店,尽享关怀
排行榜 收藏 打印 发给朋友 举报 来源: 互联网   发布者:网络转载
热度9票  浏览196次 【共0条评论】【我要评论 时间:2008年4月29日 22:30

&QG6t'^}5~0所谓保持在底部就是: 在内容不超过一屏的情况下, 当浏览器窗口变小那行页脚文字会跟着向上浮动但还是保持在底部。当内容多出一屏时,他显示在网页的最下边,而不是窗口的最下边;测了一下,还可以,在IE6、IE7、FIREOFX等都没有问题! 窗口缩小时也没有问题!齐鲁公社d/LH3Lf MdKQ
齐鲁公社!x t~+U.E.@z6d

r2mY y e!V0CODE:齐鲁公社T7L*aA+B-K [
<script language="JavaScript" type="text/javascript"> 齐鲁公社C?8w)ng @#o
function test(){ 齐鲁公社 Z5N2]Z7]p0C^5_h-t
 var infoHeight = document.getElementById("info").scrollHeight;
a^;nU3M:RM0H.R0 var bottomHeight = document.getElementById("bottom").scrollHeight;
z_ g*Wk1y6FM0 var allHeight = document.documentElement.clientHeight;
y+w+w&V{B{*M,s0 var bottom = document.getElementById("bottom"); 齐鲁公社9~0QYV O"V MoF
 if((infoHeight + bottomHeight) < allHeight){
qr qx Q*D|s9}0  bottom.style.position = "absolute";
]"_l3XJX0  bottom.style.bottom = "0";
/Fn b3D)UTN!T0 }else{ 齐鲁公社/L2fh!o4Vr M
  bottom.style.position = ""; 齐鲁公社5oj1q+QaI+R4_
  bottom.style.bottom = "";
F:A*[+Zq2}B0 }  齐鲁公社5u4@|y:St'~k
 setTimeout(function(){test();},10); 齐鲁公社2a-aG qbN8H#z.})j
} 齐鲁公社e b!VMG9| z
test();
u~(R3Z\ z B)z _0</script>齐鲁公社wr5H3y]x f Y0}

齐鲁公社SSA1^!l;~)d[ M

您可以试着运行一下代码观看效果:

2r p!f;y$EJ0

\8m-e\?4n0<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 齐鲁公社%[4f3L[v;`
<html xmlns="http://www.w3.org/1999/xhtml"> 齐鲁公社0t'SB`8{u~+@
<head>
3ZX:f!Q~0<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
H'?m$}(_7v0<title>www.jb51.net <a href="http://www.jb51.net" target="_blank"><font color=red>脚本</font></a>之家</title> 齐鲁公社Vgj/n'L `X7O
<style>
4S1Y&[ LH)B7R!j0*{ margin:0; padding:0}
$y6^F1N[;| PJ0#info{background:#33CCFF}
vp.Z j4| l0#bottom{background:#FFCC00;width:100%;}
oI}5Q~1R{;Lj(I0</style>
6rQ2xykAc*p0</head>
6W6d"{u X0<body> 齐鲁公社c4eO:u$OC
<div id="info"> 齐鲁公社3iAuF:Yk3pa

齐鲁公社Y'lU gO"d&\

2齐鲁公社4X}y G'yy E
2
+])zrei3^ l [4V02

6Hv@/q P+GQ0 齐鲁公社 Nt CF(w+J$f(h;P

2
7JD(o1?NtU02
J*oi7ep(bP02
t_3cg9z*W5h!J}3}02
)JMdBgU J!Z02齐鲁公社c*hI8@oRl&TB
2
Jknn z.B,lZ02齐鲁公社*rA-O/um @[6B-o R
2齐鲁公社jTD5_5rL4TLLo

)BEp \} ^V02
~0o ?1GD'de%H02
/rX6wH0xa$_y a02齐鲁公社1ZI!\4oC'PL
2齐鲁公社*CaNx%GW4~ Q
2齐鲁公社e'tS(x!W

$l(Dba/f+`%x02齐鲁公社L9T&IF(or$r*\aG_@
2
\BC^e:G5Vn02齐鲁公社-ug{$_[k
2
"S0he"kGy{w02齐鲁公社)c_[V } }*g!F#e&gH

QDa n'V @2_a"aW02齐鲁公社n[bJg;r0WL
2齐鲁公社MTk d&U/b1cW@8@L
2齐鲁公社-w)K7|p1d*\Va
2
C!D/ec'Z7k8P6U02齐鲁公社-iit&O;? b)b

齐鲁公社y_%uQ D BR`@(@

2
z(QK3n5FF020000</div> 齐鲁公社7ix;C];x.~:g
<div id="bottom">bottom</div>

^'M)[wCL0r0

}P g"r$aE#hq&O0<script language="JavaScript" type="text/javascript"> 齐鲁公社&SJCE*U
function test(){
z[3A0@T_] tjI0 var infoHeight = document.getElementById("info").scrollHeight; 齐鲁公社Y;IQJZU2d2`D
 var bottomHeight = document.getElementById("bottom").scrollHeight; 齐鲁公社7n2K0Vx-iqB
 var allHeight = document.documentElement.clientHeight;
xF_[P0 
PDE.F1n)^5Z fO0 var bottom = document.getElementById("bottom"); 齐鲁公社7E QU[q)~v+X,RI
 if((infoHeight + bottomHeight) < allHeight){
4E!hm)OoGhl uU0  bottom.style.position = "absolute";
D;UbqLEx"C0  bottom.style.bottom = "0";
;v qN#\R,jR/|.FL8{0 }else{ 齐鲁公社PJgs"^%}zTk
  bottom.style.position = ""; 齐鲁公社8B BW"Z6c*c C&G-G
  bottom.style.bottom = ""; 齐鲁公社'PJZ?.I s5ZA
 }  齐鲁公社}I}h k _{
  齐鲁公社2K6cz'mgVC1b5o
 setTimeout(function(){test();},10);
(S*nJ&^r0}
"}(u/X"N5Z.pZ)J0test(); 齐鲁公社_a"o}oM.x0r*p'P+h
</script> 齐鲁公社q.LUF zV/o!W
</body>
0Z{ _ipf\ D1b H0</html>

U(@2jir0
上一篇 下一篇
查看全部回复【已有0位网友发表了看法】

网络资源

合作伙伴