簡單實(shí)現(xiàn)js懸浮導(dǎo)航效果
更新時(shí)間:2017年02月05日 09:49:34 作者:萬花果子
這篇文章主要教大家如何簡單實(shí)現(xiàn)js懸浮導(dǎo)航效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了js懸浮導(dǎo)航的具體代碼,供大家參考,具體內(nèi)容如下
<head>
<meta charset="UTF-8">
<title>懸浮導(dǎo)航</title>
<style>
* {
margin: 0px;
padding: 0px;
}
ul li{
list-style: none;
}
body{
height: 2000px;
}
#top{
height: 300px;
width: 100%;
background-color: red;
}
#nav{
height: 50px;
line-height: 50px;
width: 100%;
background-color: pink;
}
#nav ul{
width: 1200px;
margin: 0 auto;
}
#nav ul li{
float: left;
width: 164px;
text-align: center;
}
</style>
</head>
<body>
<div id="top">
頂部
</div>
<div id="nav">
<ul>
<li>首頁</li>
<li>首頁</li>
<li>首頁</li>
<li>首頁</li>
<li>首頁</li>
<li>首頁</li>
<li>首頁</li>
</ul>
</div>
</body>
<script>
var ad = document.getElementById("nav")
window.onscroll = function(){
var _top = document.body.scrollTop || document.documentElement.scrollTop;//兼容
if(_top>=300){
ad.style.position = "fixed";
ad.style.top = 0 +"px";
}else{
ad.style.position = "absolute";
ad.style.top = 300+"px";
}
}
</script>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
基于javascript實(shí)現(xiàn)隨機(jī)顏色變化效果
這篇文章主要介紹了基于javascript實(shí)現(xiàn)隨機(jī)顏色變化效果的相關(guān)資料,需要的朋友可以參考下2016-01-01
Next.js路由組使用之組織路由結(jié)構(gòu)示例詳解
這篇文章主要為大家介紹了Next.js路由組使用之組織路由結(jié)構(gòu)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10
javascript獲取select標(biāo)簽選中的值
這篇文章主要介紹javascript獲取select標(biāo)簽選中的值方法,比較實(shí)用,需要的朋友可以參考下。2016-06-06
js實(shí)現(xiàn)C#的StringBuilder效果完整實(shí)例
這篇文章主要介紹了js實(shí)現(xiàn)C#的StringBuilder效果,以完整實(shí)例形式分析總結(jié)了js實(shí)現(xiàn)C#的StringBuilder效果的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-12-12
Javascript筆記一 js以及json基礎(chǔ)使用說明
JavaScript中的數(shù)據(jù)很簡潔的。簡單數(shù)據(jù)只有 undefined, null, boolean, number和string這五種,而復(fù)雜數(shù)據(jù)只有一種,即object。2010-05-05

