導覽列背景移動

來源:互聯網
上載者:User

標籤:

<!doctype html>
<html class="no-js" lang="">

<head>
<meta charset="UTF-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Untitled Document</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="apple-touch-icon" href="apple-touch-icon.png">
<!-- Place favicon.ico in the root directory -->
<link rel="stylesheet" type="text/css" href="style.css">
<script src="jquery-1.11.3.js"></script>
<script>
$(function(){
$(‘nav ul li‘).mouseenter(function(){
var _left=$(this).position().left;
var _width=$(this).width()+40;
$(‘.nav-bg‘).css("left",_left);
$(‘.nav-bg‘).css("width",_width);
});
$(‘nav‘).mouseleave(function(){

var _left=$(‘nav ul li.on‘).position().left;
var _width=$(‘nav ul li.on‘).width()+40;
$(‘.nav-bg‘).css("left",_left);
$(‘.nav-bg‘).css("width",_width);

})
})
</script>
</head>
<style>
body,html,ul{margin: 0px;padding: 0px;}
a{text-decoration: none;}
header{width: 100%;height: 40px;background: #ddd;line-height: 40px;}
nav{width: 1200px;margin: auto;position: relative;}
nav ul {position:relative;z-index: 1;overflow: hidden;}
nav ul li{width:auto;padding: 0px 20px; float: left;list-style: none;cursor: pointer;text-align: center;height: 40px;line-height: 40px;}
.nav-bg{height: 40px;background: #333;position: absolute;left: 0px;opacity: 0.2;transition-duration: .5s;z-index: 0;}
</style>
<body>

<header>
<nav>
<div class="nav-bg"></div>
<ul>
<li class="on"><a href="#">欄目標題</a></li>
<li><a href="#">欄目標題</a></li>
<li><a href="#">欄目標題</a></li>
<li><a href="#">欄目標題</a></li>
</ul>
</nav>

</header>
</body>
</html>

導覽列背景移動

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.