JS实现让页脚一直固定在页面底部问题 本帖最后由 zyz_0420 于 2013-06-02 15:02:20 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $(window).bind("load", function() { var footerHeight = 0; var footerTop = 0; positionFooter(); function positionFooter() { footerHeight = $("#footer").height(); footerTop = ($(window).scrollTop()+$(window).height()-footerHeight)+"px"; //如果页面内容高度小于屏幕高度,div#footer将绝对定位到屏幕底部,否则div#footer保留它的正常静态定位 if(($(document.body).height()+footerHeight) < $(window).height()) { $("#footer").css({ position: "absolute",left:"0" }).stop().css({top:footerTop}); } } $(window).scroll(positionFooter).resize(positionFooter);}); 您好,朋友!还有个问题想请教:如以下代码,点击header中对应的 a 标签,切换main中对应的div内容,如何写JS?<html><head></head><body> <div id="header"> <a href="#">1111111</a><br /> <a href="#">2222222</a><br /> <a href="#">3333333</a><br /> </div> <div id="main"> <div class="1">1111111</div> <div class="2">2222222</div> <div class="3">3333333</div> </div></body></html> 点机1111111,显示<div class="1">,2222222显示<div class="2">,3333333显示<div class="3">吗?最简单的方法是为main层的div加id,给锚点加id.例如:<a id="anchor1">,...<div id="anchor1_main">,... main中的1111111,2222222....,默认只显示一个,如:默认显示的是1111111,当点击<a href="#">2222222</a><br />时,就显示2222222 <!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>无标题文档</title><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><style type="text/css">a.on{color:#f00}#main div.on{background-color:#f00;display:block;}#main div{display:none;}</style></head><body> <div id="header"> <a id="anchor1" class="on" href="#">1111111</a><br /> <a id="anchor2" href="#">2222222</a><br /> <a id="anchor3" href="#">3333333</a><br /> </div> <div id="main"> <div id="anchor1_main" class="on">1111111</div> <div id="anchor2_main">2222222</div> <div id="anchor3_main">3333333</div> </div><script type="text/javascript">jQuery(function($){ $('a').click(function(){ var att=$(this).attr('id'); var attmain='#'+att+'_main'; $('#header').find('a').not($(this)).removeClass('on'); $(this).addClass('on'); $('#main').find('div').not($(attmain)).removeClass('on'); $(attmain).addClass('on'); });});</script></body></html> 不好意思,又要麻烦您帮忙看看啊!源码地址:http://pan.baidu.com/share/link?shareid=2825682553&uk=1745185362 他就应该是这样的呀,默认的情况下main>div 的高度为999px,切换后其高度为0 当main内容少于页面可视高度时页脚应该置于页面底部才对啊 请教关闭弹出层的问题 JQUERY新增元素的事件绑定问题 js不兼容火狐的问题。。求教 google map 二次开发的问题 请教大师一个jquery的问题 webgame地图生成及应用 為何每要刷新一下才能下載. 难道是js的一个bug? 在弹出菜单里不能给select元素加入option元素! 请问,删除表单里的一行该用什么命令? 第二个也应该是juqery对象啊 求一类正则表达式的写法 JS设置读取cookie问题,是不是cookie的设置与读取有延时?
$(window).bind("load", function() {
var footerHeight = 0;
var footerTop = 0;
positionFooter();
function positionFooter() {
footerHeight = $("#footer").height();
footerTop = ($(window).scrollTop()+$(window).height()-footerHeight)+"px";
//如果页面内容高度小于屏幕高度,div#footer将绝对定位到屏幕底部,否则div#footer保留它的正常静态定位
if(($(document.body).height()+footerHeight) < $(window).height()) {
$("#footer").css({ position: "absolute",left:"0" }).stop().css({top:footerTop});
}
}
$(window).scroll(positionFooter).resize(positionFooter);
});
<html>
<head>
</head>
<body>
<div id="header">
<a href="#">1111111</a><br />
<a href="#">2222222</a><br />
<a href="#">3333333</a><br />
</div> <div id="main">
<div class="1">1111111</div>
<div class="2">2222222</div>
<div class="3">3333333</div>
</div>
</body>
</html>
最简单的方法是为main层的div加id,给锚点加id.例如:
<a id="anchor1">,...
<div id="anchor1_main">,...
<!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>无标题文档</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<style type="text/css">
a.on{color:#f00}#main div.on{background-color:#f00;display:block;}
#main div{display:none;}
</style>
</head><body>
<div id="header">
<a id="anchor1" class="on" href="#">1111111</a><br />
<a id="anchor2" href="#">2222222</a><br />
<a id="anchor3" href="#">3333333</a><br />
</div>
<div id="main">
<div id="anchor1_main" class="on">1111111</div>
<div id="anchor2_main">2222222</div>
<div id="anchor3_main">3333333</div>
</div>
<script type="text/javascript">
jQuery(function($){
$('a').click(function(){
var att=$(this).attr('id');
var attmain='#'+att+'_main';
$('#header').find('a').not($(this)).removeClass('on');
$(this).addClass('on');
$('#main').find('div').not($(attmain)).removeClass('on');
$(attmain).addClass('on');
});
});
</script>
</body>
</html>
不好意思,又要麻烦您帮忙看看啊!
源码地址:http://pan.baidu.com/share/link?shareid=2825682553&uk=1745185362