那麼我們應該如何?流動導覽功能表呢?
一、
滑鼠滑過Menu,即Show提示資訊。
二、實現步驟
1、CSS代碼 複製代碼 代碼如下:menuBarHolder { width: 730px; height:45px; background-color:#000; color:#fff; font-family:Arial; font-size:14px; margin-top:20px;}
#menuBarHolder ul{ list-style-type:none; display:block;}
#container { margin-top:100px;}
#menuBar li{ float:left; padding:15px; height:16px; width:50px; border-right:1px solid #ccc; }
#menuBar li a{color:#fff; text-decoration:none; letter-spacing:-1px; font-weight:bold;}
.menuHover { background-color:#999;}
.firstchild { border-left:1px solid #ccc;}
.menuInfo { cursor:hand; background-color:#000; color:#fff;
width:74px; font-size:11px;height:100px; padding:3px; display:none;
position:absolute; margin-left:-15px; margin-top:-15px;
-moz-border-radius-bottomright: 5px;
-moz-border-radius-bottomleft: 5px;
-webkit-border-bottom-left-radius: 5px;
-webkit-border-bottom-right-radius: 5px;
-khtml-border-radius-bottomright: 5px;
-khtml-border-radius-bottomleft: 5px;
border-radius-bottomright: 5px;
border-radius-bottomleft: 5px;
}
menuBarHolder: 菜單Menu的固定容器,寬度=730px。
menuInfo:控制提示資訊的展示與否。
2、HTML代碼 複製代碼 代碼如下:<div id="menuBarHolder">
<ul id="menuBar">
<li class="firstchild"><a href="javascript:#">Home</a>
<div class="menuInfo">I am some text about the home section</div></li>
<li><a href="javascript:#">Services</a>
<div class="menuInfo">I am some text about the services section</div></li>
<li><a href="javascript:#">Clients</a>
<div class="menuInfo">I am some text about the clients section</div></li>
<li><a href="javascript:#">Portfolio</a>
<div class="menuInfo">I am some text about the portfolio section</div></li>
<li><a href="javascript:#">About</a>
<div class="menuInfo">I am some text about the about section</div></li>
<li><a href="javascript:#">Blog</a>
<div class="menuInfo">I am some text about the blog section</div></li>
<li><a href="javascript:#">Follow</a>
<div class="menuInfo">I am some text about the follow section</div></li>
<li><a href="javascript:#">Contact</a>
<div class="menuInfo">I am some text about the contact section</div></li>
</ul>
</div>
UI LI元素:列表元素。
DIV元素:提示內容資訊。
3、Javascript代碼 複製代碼 代碼如下:$(document).ready(function()
{
$('#menuBar li').click(function()
{
var url = $(this).find('a').attr('href');
document.location.href = url;
});
$('#menuBar li').hover(function()
{
$(this).find('.menuInfo').slideDown();
},
function()
{
$(this).find('.menuInfo').slideUp();
});
});
click()、 hover():給Li元素繫結單擊事件和滑鼠滑過事件。
find()函數:搜尋所有與指定運算式匹配的元素。這個函數是找出正在處理的元素的後代元素的好方法。
slideDown(speed, [callback]):通過高度變化(向下增大)來動態地顯示所有匹配的元素,在顯示完成後可選地觸發一個回呼函數。
slideUp(speed, [callback]):通過高度變化(向上減小)來動態地隱藏所有匹配的元素,在隱藏完成後可選地觸發一個回呼函數。 <br /><style type="text/css"> #menuBarHolder { width: 730px; height:45px; background-color:#000; color:#fff; font-family:Arial; font-size:14px; margin-top:20px;} #menuBarHolder ul{ list-style-type:none; display:block;} .firstchild { border-left:1px solid #ccc;} #container { margin-top:100px;} #menuBar li{ float:left; padding:15px; height:16px; width:50px; border-right:1px solid #ccc; } #menuBar li a{color:#fff; text-decoration:none; letter-spacing:-1px; font-weight:bold;} .menuHover { background-color:#999;} .menuInfo { cursor:hand; background-color:#000; color:#fff; width:74px; font-size:11px;height:100px; padding:3px; display:none; position:absolute; margin-left:-15px; margin-top:-15px; -moz-border-radius-bottomright: 5px; -moz-border-radius-bottomleft: 5px; -webkit-border-bottom-left-radius: 5px; -webkit-border-bottom-right-radius: 5px; -khtml-border-radius-bottomright: 5px; -khtml-border-radius-bottomleft: 5px; border-radius-bottomright: 5px;border-radius-bottomleft: 5px; } h1 { font: 50px normal Georgia, 'Times New Roman', Times, serif; color: #111; margin: 0; text-align: center; padding: 5px 0; </p><p>} h1 small{ font: 0.2em normal Verdana, Arial, Helvetica, sans-serif; text-transform:uppercase; letter-spacing: 1.4em; display: block; color: #ccc; } </style><p><!--[if IE]> </p><style type="text/css"> #menuBar li a{width:50px;} .menuInfo { margin-left:-65px; width:80px;} </style><p><![endif]--><center> </p>Fluid Navigation<br />CSS & jQuery <small>Tutorial by Addy Osmani</small><ul id="menuBar"><li class="firstchild">HomeI am some text about the home section</li><li>ServicesI am some text about the services section</li><li>ClientsI am some text about the clients section</li><li>PortfolioI am some text about the portfolio section</li><li>AboutI am some text about the about section</li><li>BlogI am some text about the blog section</li><li>FollowI am some text about the follow section</li><li>ContactI am some text about the contact section</li></ul><p></center><br />