原生js吸頂式導航條

來源:互聯網
上載者:User

標籤:int   高度   isp   pad   ext   var   block   dex   ret   

<!--吸頂式導航條-->
<nav class="nav">
<div>
<a href="javascript: return false"><img
src="n.jpg" ></a>
<div class="topNav">
<div>
<input type="text" placeholder="iPhone 6低至2299元">
<a href="#"><img src="img/fdj.png"></a>
</div>
</div>
</div>
</nav>

/*吸頂式導航條css樣式*/
/*——start——*/
body>nav{
position: fixed;
z-index: 1000;
top: -60px;
width: 100%;
height: 60px;
border-bottom: 1px solid #dfdfdf;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
background-color: #fff;
transition: top 0.4s ease;
}
body>nav>div{
width: 1228px;
margin: 0 auto;
}
body>nav>div>a{
display: block;
width: 150px;
height: 60px;
float: left;
margin-right: 47px;
}
body>nav>div>a>img{
width: 150px;
height: 60px;
}
/*輸入框樣式*/
.topNav>div>input{
width: 702px;
height: 36px;
border: 0 none;
margin-bottom: 1px;
padding-left: 15px;
font-size: 14px;
color: #aaa;
outline:none;
line-height: 36px;
}
/*搜尋按鈕樣式*/
.topNav>div>a{
float: left;
width: 50px;
height: 36px;
border: 0 none;
margin-left: 700px;
margin-top: -36px;
background-color: #ff4040;
text-align: center;
line-height: 36px;
color: #fff;
}
.topNav>div>a>img{
width: 28px;
height: 28px;
margin-top: 2px;
margin-left: 3px;
}
/*搜尋盒子背景樣式*/
.topNav>div{
float: left;
width: 750px;
padding: 3px 2px 2px 2px;
margin-top: 10px;
border-radius: 2px;
background-color: #ff4040;
}
/*——end——*/

// 吸頂式導航條js監測
/*——start——*/
var nav = function () {
var topNav = document.querySelectorAll(".nav");
/*儲存當前Y軸捲軸高度*/
var onscrHei = pageYOffset;
if (onscrHei > 670) {
topNav[0].style.top = "0px";
} else {
topNav[0].style.top = "-60px";
}
};
setInterval("nav()", 100);
/*——end——*/

原生js吸頂式導航條

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.