本範例示範如何以 jQuery 製作一個具備滑入動畫效果的橫向導航選單,滑鼠移入時文字會上下滑動切換,視覺相當細緻。
效果體驗:
https:///keleyi/phtml/jqtexiao/39.htm
HTML 檔案程式碼:
<!DOCTYPE html>
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title>jQuery 簡單漂亮的導航選單 - </title><base target="_blank" />
<link href="https:///keleyi/phtml/jqtexiao/39/hovertreedaohang.css" rel="stylesheet" type="text/css" />
<script src="https://hovertree.com/ziyuan/jquery/jquery-1.11.3.min.js"></script>
<script>
$(document).ready(function() {
$("#hovertreecaidan li a").wrapInner( '<span class="out"></span>' );
$("#hovertreecaidan li a").each(function() {
$( '<span class="over">' + $(this).text() + '</span>' ).appendTo( this );
});
$("#hovertreecaidan li a").hover(function() {
$(".out", this).stop().animate({'top': '48px'}, 300); // move down - hide
$(".over", this).stop().animate({'top': '0px'}, 300); // move down - show
}, function() {
$(".out", this).stop().animate({'top': '0px'}, 300); // move up - show
$(".over", this).stop().animate({'top': '-48px'}, 300); // move up - hide
});
});
</script>
<style>.keleyicenter{width:820px;margin:2px auto;}</style>
</head>
<body>
<div class="keleyicenter"><h2>jQuery 簡單漂亮的導航選單</h2></div>
<div id="hovertreecaidan" class="hovertreedaohang">
<ul>
<li><a href="https://">首 頁</a></li>
<li><a href="https:///menu/jquery/">jQuery</a></li>
<li><a href="https:///menu/webqd/">Web前端</a></li>
<li><a href="https:///a/bjae/5ntk26xt.htm">原文</a></li>
<li><a href="https:///menu/html5/">HTML5</a></li>
<li><a href="https://hovertree.com/">HoverTree</a></li>
<li><a href="https://hovertree.com/texiao/">網頁特效</a></li>
<li><a href="https://tool./">工具</a></li>
<li><a href="https://hovertree.com/guestbook/">留言</a></li>
</ul>
<div class="hvtclear"></div>
</div>
</body>
</html>
其中 jQuery 的 wrapInner() 方法會使用指定的 HTML 內容或元素,來包裹每個被選元素中的所有內容(inner HTML)。
參考:https://hovertree.com/hvtart/bjae/m66osaoc.htm