这篇文章给大家分享的是有关css如何实现网页栏目左侧固定当滚动到底部时自动调整位置 的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
预览地址:
https://ovsexia.gitee.io/leftfixed/
html:
<!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" />
<script src="js/jquery-1.10.1.min.js" type="text/javascript"></script>
<link href="css/layout.css" type="text/css" rel="stylesheet" />
<link href="css/style.css" type="text/css" rel="stylesheet" />
</head>
<div class="top"></div>
<div class="page">
<div class="left">
<div class="left_poi"></div>
<div class="left_in">
<p><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 /></p>
</div><!--left_in-->
<script>
$(window).scroll(function()
{
saction();
});
function saction()
{
sj = 20; //底部间隔
st = $(window).scrollTop(); //滚动条高度
sd = $(".left_poi").offset().top;
sd_h = $(".left_in").height();
sb = $(".bottom").offset().top;
sb_h = $(".bottom").height();
rd_h = $(".right").height();
bh = window.innerHeight;
si = sb-sd_h;
if(st>sd && rd_h>=sd_h){
$(".left_in").addClass("on");
if(st>si){
sy = bh-(sb-st)+sj;
$(".left_in").css({"top":"auto","bottom":sy+"px"});
}else{
$(".left_in").css({"top":"","bottom":""});
}
}else{
$(".left_in").removeClass("on");
}
}
</script>
</div><!--left-->
<div class="right"></div>
<div class="clear"></div>
</div><!--page-->
<div class="bottom"></div>
</body>
</html>
css
@charset "utf-8";
.clear {clear:both; height:0 !important; width:0 !important; overflow:hidden; font-size:0;}
.top {width:100%; height:150px; background:#0CC;}
.bottom {width:100%; height:400px; background:#39C;}
.page {width:1200px; margin:20px auto; position:relative;}
.left {width:200px; float:left;}
.left_in {width:200px; background:#46bc67; border-top:3px solid #000; border-bottom:3px solid #000;}
.left_in.on {position:fixed; top:0;}
.left_poi {width:100%; height:1px; overflow:hidden;}
.right {width:960px; height:2100px; float:right; overflow:hidden; background:#FC3;}
感谢各位的阅读!关于“css如何实现网页栏目左侧固定当滚动到底部时自动调整位置 ”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://www.jb51.net/css/675513.html