当前位置: 首页 > 图文教程 > 网络编程 > Javascript > jQuery 渐变下拉菜单

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 jQuery 渐变下拉菜单


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 357 ::
收藏到网摘: n/a

利用jQuery来实现,其实就几行代码的事。即便如此,由于js语言的思维方式,还是一直没有把握好,加上一个css的问题,导致弄了好久才出来效果。 这里主要是利目标在鼠标经过时(.hover())利用slideToggle() 、slideUp()来显示原来隐藏着的内容:
复制代码 代码如下:

$(function(){
$(".dropdown").hover(
function(){ $("li ul").slideToggle(800);},
function(){$("li ul").slideUp(1000)}
)
})


复制代码 代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery 渐变下来效果</title>
<style type="text/css">
a{text-decoration:none;color:#333;}
a:hover{color:#f33;}
a.gr{color:#227CE8;}
a.xg{color:#f30;}
a.zx{color:#690;}
a.yd{color:#f00;}
a.more-rss{color:#f60;}
a img{border:none;}
a.rssfeed{display:block;height:60px;width:160px;cursor:pointer;}
.wrapper{width:700px;margin:0 auto;height:460px;position:relative;}
.wrapper small{position:absolute;bottom:0;left:0;border-top:1px dotted #b3b3b3;display:block;width:700px;line-height:30px;text-align:right;}
ul li{list-style:none;}
ul li.dropdown{position:relative;width:160px;}
ul li.dropdown ul{display:none;text-align:center;background:#fff;border:1px solid #ddd;width:160px;padding:15px 15px 20px;}
ul li.dropdown ul li{padding:5px 0;border-bottom:1px dotted #ddd;}
</style>
</head>
<body>
<div class="wrapper">
<h1><a href="">jQuery 渐变下拉菜单</a></h1>
<p>使用slideToggle和slideUp来实现.当然,也可以使用hide/show, fadeIn/fadeOut等来实现,只是效果不同,实现的方法还是相同的.需要注意的是,要给.dropdown加上position:relative;防止闪烁.</p>
<ul class="fir">
<li class="dropdown">
<a class="rssfeed"><img src="feedme.png" alt="feedme" /></a>
<ul>
<li><a href="#" rel="RSS"><img src="rss.gif" alt="RSS Feed" /></a></li>
<li><a href="#" class="xg" rel="nofollow">鲜果订阅</a></li>
<li><a href="#" class="gr" rel="nofollow">Google订阅</a></li>
<li><a href="#" class="zx" rel="nofollow">抓虾订阅</a></li>
<li><a href="#" class="yd" rel="nofollow">有道订阅</a></li>
<li><a href="#" class="more-rss" rel="RSS">更多方式 »</a></li>
</ul>
</li>
</ul>
</div>
<script language="javascript" type="text/javascript" src="jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(function(){
$(".fir .dropdown").hover(
function(){
$("li ul").slideToggle(800);
},function(){
$("li ul").slideUp(1000)
})
})
</script>
</body>
</html>

测试代码打包下载