css實(shí)現(xiàn)網(wǎng)頁(yè)欄目左側(cè)固定當(dāng)滾動(dòng)到底部時(shí)自動(dòng)調(diào)整位置
發(fā)布時(shí)間:2019-05-29 14:44:54 作者:佚名
我要評(píng)論

這篇文章主要介紹了css實(shí)現(xiàn)網(wǎng)頁(yè)欄目左側(cè)固定當(dāng)滾動(dòng)到底部時(shí)自動(dòng)調(diào)整位置 ,需要的朋友可以參考下
預(yù)覽地址:
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(); //滾動(dòng)條高度 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;}
總結(jié)
以上所述是小編給大家介紹的css實(shí)現(xiàn)網(wǎng)頁(yè)欄目左側(cè)固定當(dāng)滾動(dòng)到底部時(shí)自動(dòng)調(diào)整位置 ,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
- 最近小編接了一個(gè)項(xiàng)目需要實(shí)現(xiàn)手機(jī)端底部tab欄切換功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2020-04-22