玩转动感滑动透明菜单(一)
2007-11-27 16:10:53 来源:WEB开发网 闂傚倸鍊搁崐鎼佸磹閹间礁纾归柟闂寸绾惧綊鏌熼梻瀵割槮缁炬儳缍婇弻鐔兼⒒鐎靛壊妲紒鐐劤缂嶅﹪寮婚悢鍏尖拻閻庨潧澹婂Σ顔剧磼閻愵剙鍔ょ紓宥咃躬瀵鎮㈤崗灏栨嫽闁诲酣娼ф竟濠偽i鍓х<闁绘劦鍓欓崝銈囩磽瀹ュ拑韬€殿喖顭烽幃銏ゅ礂鐏忔牗瀚介梺璇查叄濞佳勭珶婵犲伣锝夘敊閸撗咃紲闂佽鍨庨崘锝嗗瘱闂備胶顢婂▍鏇㈠箲閸ヮ剙鐏抽柡鍐ㄧ墕缁€鍐┿亜韫囧海顦﹀ù婊堢畺閺屻劌鈹戦崱娆忓毈缂備降鍔庣划顖炲Φ閸曨垰绠抽悗锝庝簽娴犻箖姊洪棃娑欐悙閻庢矮鍗抽悰顕€宕堕澶嬫櫖濠殿噯绲剧€笛囧箲閸ヮ剙钃熼柣鏂挎憸閻熷綊鏌涢…鎴濇灈妞ゎ剙鐗嗛—鍐Χ鎼粹€茬凹缂備緡鍠楅幐鎼佹偩閻戣棄纭€闁绘劕绉靛Λ鍐春閳ь剚銇勯幒鎴濐伀鐎规挷绀侀埞鎴︽偐閹绘帩浼€缂佹儳褰炵划娆撳蓟濞戞矮娌柟瑙勫姇椤ユ繈姊洪柅鐐茶嫰婢т即鏌熼搹顐e磳闁挎繄鍋涢埞鎴犫偓锝庘偓顓涙櫊閺屽秵娼幏灞藉帯闂佹眹鍊曢幊鎰閹惧瓨濯撮柛鎾村絻閸撳崬顪冮妶鍡楃仸闁荤啿鏅涢悾鐑藉Ψ瑜夐崑鎾绘晲鎼粹剝鐏嶉梺缁樻尰濞叉﹢濡甸崟顖氱疀闂傚牊绋愮花鑲╃磽娴h棄鐓愭慨妯稿妿濡叉劙骞樼拠鑼槰闂佸啿鎼崐濠毸囬弶搴撴斀妞ゆ梻銆嬪銉︺亜椤撶偛妲婚柣锝囧厴楠炴帡骞嬮弮鈧悗濠氭⒑鐟欏嫭鍎楅柛妯衡偓鐔插徍濠电姷鏁告慨鐑藉极閸涘﹥鍙忔い鎾卞灩绾惧鏌熼崜褏甯涢柍閿嬪灦閵囧嫰骞掗崱妞惧缂傚倷绀侀ˇ閬嶅极婵犳氨宓侀柛鈩冪⊕閸婄兘鏌涘┑鍡楊伀妞ゆ梹鍔曢埞鎴︽倻閸モ晝校闂佸憡鎸婚悷锔界┍婵犲洦鍤冮柍鍝勫暟閿涙粓姊鸿ぐ鎺戜喊闁告瑥楠搁埢鎾斥堪閸喓鍘搁柣蹇曞仧绾爼宕戦幘璇茬疀濞达絽鎲¢崐顖炴⒑绾懎浜归悶娑栧劦閸┾偓妞ゆ帒鍟惃娲煛娴e湱澧柍瑙勫灴閹瑩寮堕幋鐘辨闂備礁婀辨灙闁硅姤绮庨崚鎺楀籍閸喎浠虹紓浣割儓椤曟娊鏁冮崒娑氬幈闂佸搫娲㈤崝宀勬倶閻樼粯鐓曢柟鑸妼娴滄儳鈹戦敍鍕杭闁稿﹥鐗犲畷婵嬫晝閳ь剟鈥﹂崸妤€鐒垫い鎺嶈兌缁犲墽鈧厜鍋撳┑鐘辩窔閸嬫鈹戦纭烽練婵炲拑绲垮Σ鎰板箳閹冲磭鍠撻幏鐘绘嚑閼稿灚姣愰梻鍌氬€烽懗鑸电仚濠电偛顕崗妯侯嚕椤愩倖瀚氱€瑰壊鍠栧▓銊︾節閻㈤潧校缁炬澘绉瑰鏌ュ箵閹烘繄鍞甸柣鐘烘鐏忋劌顔忛妷褉鍋撶憴鍕碍婵☆偅绻傞~蹇涙惞閸︻厾锛滃┑鈽嗗灠閹碱偊锝炲鍥╃=濞达綁顥撻崝宥夋煙缁嬪灝鏆遍柣锝囧厴楠炲鏁冮埀顒傜不婵犳碍鍋i柛銉戝啰楠囬悗瑙勬尭缁夋挳鈥旈崘顔嘉ч柛鈩兠棄宥囩磽娴e壊鍎愰柛銊ュ缁顓兼径瀣偓閿嬨亜閹哄秶顦︾€殿喖鐏濋埞鎴﹀煡閸℃浠梺鍛婎焼閸曨収娲告俊銈忕到閸燁垶宕愰崹顐e弿婵☆垳鍘ф禍楣冩倵濮樼偓瀚�

<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN>
<HTML><HEAD><TITLE>玩转动感滑动透明菜单(一)</TITLE>
<!-- Make By CSDN Nba23 8/6/2003 ) -->
<META content=text/html; charset=gb2312 http-equiv=Content-Type>
<META content=MSHTML 5.00.3502.5390 name=GENERATOR>
<STYLE type=text/css></STYLE>
<LINK href=images/sytle.css rel=stylesheet type=text/css>
<SCRIPT language=javascript src=images/dropdownC.js>
</SCRIPT>
<SCRIPT language=javascript src=images/dropdown_initialize.js>
</SCRIPT>
</HEAD>
<BODY bgcolor=#FDEEEE onload=init();>
<p> 玩转动感滑动透明菜单(一):(Make By <em>CSDN</em> <em><strong><a href=mailto:nba23@vbnc.net>nba23</a></strong></em>
8/6/2003 )<br>
</p>
<TABLE width=70% border=0 align=center cellPadding=0 cellSpacing=0 >
<TBODY>
<TR>
<TD vAlign=top height=24><A id=menu1
onmouseover=swapImage(button1, preloaded[1][1].src)
onmouseout=swapImage(button1, preloaded[1][0].src)
href=http://www.csdn.net><IMG src=http://www.chinageren.com/chengxu/Javascript/images/1-0.gif
name=button1 width=68 height=25 border=0
id=button1></A></TD>
<TD vAlign=top height=24><a id=menu2
onMouseOver=swapImage(button2, preloaded[2][1].src)
onMouseOut=swapImage(button2, preloaded[2][0].src)
href=http://www.csdn.net><img src=http://www.chinageren.com/chengxu/Javascript/images/2-0.gif
name=button2 width=68 height=25 border=0
id=button2></a></TD>
<TD vAlign=top height=24><A id=menu3
onmouseover=swapImage(button3, preloaded[3][1].src)
onmouseout=swapImage(button3, preloaded[3][0].src)
href=http://www.csdn.net><IMG src=http://www.chinageren.com/chengxu/Javascript/images/3-0.gif
name=button3 width=68 height=25 border=0
id=button3></A></TD>
<TD vAlign=top height=24><A id=menu4
onmouseover=swapImage(button4, preloaded[4][1].src)
onmouseout=swapImage(button4, preloaded[4][0].src)
href=http://www.csdn.net><IMG src=http://www.chinageren.com/chengxu/Javascript/images/4-0.gif
name=button4 width=68 height=25 border=0
id=button4></A></TD>
<TD vAlign=top height=24><A id=menu5
onmouseover=swapImage(button5, preloaded[5][1].src)
onmouseout=swapImage(button5, preloaded[5][0].src)
href=http://www.csdn.net><IMG src=http://www.chinageren.com/chengxu/Javascript/images/5-0.gif
name=button5 width=68 height=25 border=0
id=button5></A></TD>
<TD vAlign=top height=24><A id=menu6
onmouseover=swapImage(button6, preloaded[6][1].src)
onmouseout=swapImage(button6, preloaded[6][0].src)
href=http://www.csdn.net><IMG
src=http://www.chinageren.com/chengxu/Javascript/images/6-0.gif
name=button6 width=68 height=25 border=0 id=button6></A></TD>
</TR></TBODY></TABLE>
<SCRIPT language=javascript src=images/dropdown_content.js>
</SCRIPT>
<!-- JS文件和gif图片(以1-0、1-1、2-0、2-1 .....命名)保存在images目录下 -->
<br>
<CENTER>
<a >演示</a>:http://www.vbnc.net/nba23/js/menu10.htm<br>
<a >下载代码</a>:http://www.vbnc.net/nba23/js/menu10.rar<br>
</CENTER><br></BODY></HTML>
sytle.css
--------------------------------
A{
COLOR: #ooo; TEXT-DECORATION:none
}
A:link {
COLOR: #039
}
A:visited {
COLOR: #039
}
A:hover {
COLOR: #f60
}
.mtDropdownMenu {
LEFT: -1imagespx; OVERFLOW: hidden; POSITION: absolute; TOP: -1imagespx
}
.mtDropdownMenu .content {
POSITION: absolute
}
.mtDropdownMenu .items {
BORDER-BOTTOM: #999 1px solid; BORDER-LEFT: #999 1px solid; BORDER-RIGHT: #999 1px solid; BORDER-TOP: #999 1px solid; LEFT: 0px; POSITION: relative; TOP: 0px; Z-INDEX: 2
}
.mtDropdownMenu .item {
BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-RIGHT: medium none; BORDER-TOP: medium none; COLOR: #333333; CURSOR: hand; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 12px; TEXT-DECORATION: none; EXT-DECORATION: none
}
.mtDropdownMenu .background {
FILTER: alpha(opacity=75); LEFT: 0px; POSITION: absolute; TOP: 0px; Z-INDEX: 1; moz-opacity: .8
}
.mtDropdownMenu .shadowRight {
FILTER: alpha(opacity=40); POSITION: absolute; TOP: 3px; WIDTH: 2px; Z-INDEX: 3; moz-opacity: .4
}
.mtDropdownMenu .shadowBottom {
FILTER: alpha(opacity=40); HEIGHT: 2px; LEFT: 3px; POSITION: absolute; Z-INDEX: 1; moz-opacity: .4
}
.mtDropdownMenu .hover {
BACKGROUND: #cccccc; COLOR: #ffffff
}
.mtDropdownMenu .item IMG {
MARGIN-LEFT: 10px
}
dropdownC.js
-----------------------------------------
<!--
mtDropDown.spacerGif = ;
mtDropDown.dingbatOn = ;
mtDropDown.dingbatOff = ;
mtDropDown.dingbatSize = 14;
mtDropDown.menuPadding = 1;
mtDropDown.itemPadding = 4;
mtDropDown.shadowSize = 2;
mtDropDown.shadowOffset = 3;
mtDropDown.shadowColor = #888; //菜单边框阴影
mtDropDown.shadowPng = ;
mtDropDown.backgroundColor = #ffffff; //菜单底色
mtDropDown.backgroundPng = ;
mtDropDown.hideDelay = 200; //菜单隐藏时间
mtDropDown.slideTime = 300; //菜单显示时间
mtDropDown.reference = {topLeft:1,topRight:2,bottomLeft:3,bottomRight:4};
mtDropDown.direction = {down:1,right:2};
mtDropDown.registry = [];
mtDropDown._maxZ = 100;
mtDropDown.isSupported = function() {
if (typeof mtDropDown.isSupported.r == boolean)
return mtDropDown.isSupported.r;
var ua = navigator.userAgent.toLowerCase();
var an = navigator.appName;
var r = false;
if (ua.indexOf(gecko) > -1) r = true;
else if (an == Microsoft Internet Explorer) {
if (document.getElementById) r = true;
}
mtDropDown.isSupported.r = r;
return r;
}
mtDropDown.initialize = function() {
for (var i = 0, menu = null; menu = this.registry[i]; i++) {
menu.initialize();
}
}
mtDropDown.renderAll = function() {
var aMenuHtml = [];
for (var i = 0, menu = null; menu = this.registry[i]; i++) {
aMenuHtml[i] = menu.toString();
}
document.write(aMenuHtml.join());
}
function mtDropDown(oActuator, iDirection, iLeft, iTop, iReferencePoint, parentMenuSet) {
this.addItem = addItem;
this.addMenu = addMenu;
this.toString = toString;
this.initialize = initialize;
this.isOpen = false;
this.show = show;
this.hide = hide;
this.items = [];
this.onactivate = new Function();
this.ondeactivate = new Function();
this.onmouseover = new Function();
this.onqueue = new Function();
this.index = mtDropDown.registry.length;
mtDropDown.registry[this.index] = this;
var id = mtDropDown + this.index;
var contentHeight = null;
var contentWidth = null;
var childMenuSet = null;
var animating = false;
var childMenus = [];
var slideAccel = -1;
var elmCache = null;
var ready = false;
var _this = this;
var a = null;
var pos = iDirection == mtDropDown.direction.down ? top : left;
var dim = null;
function addItem(sText, sUrl) {
var item = new mtDropDownItem(sText, sUrl, this);
item._index = this.items.length;
this.items[item._index] = item;
}
function addMenu(oMenuItem) {
if (!oMenuItem.parentMenu == this) throw new Error(Cannot add a menu here);
if (childMenuSet == null) childMenuSet = new mtDropDownSet(mtDropDown.direction.right, -5, 2, mtDropDown.reference.topRight);
var m = childMenuSet.addMenu(oMenuItem);
childMenus[oMenuItem._index] = m;
m.onmouseover = child_mouseover;
m.ondeactivate = child_deactivate;
m.onqueue = child_queue;
return m;
}
function initialize() {
initCache();
initEvents();
initSize();
ready = true;
}
function show() {
if (ready) {
_this.isOpen = true;
animating = true;
setContainerPos();
elmCache[clip].style.visibility = visible;
elmCache[clip].style.zIndex = mtDropDown._maxZ++;
slideStart();
_this.onactivate();
}
}
function hide() {
if (ready) {
_this.isOpen = false;
animating = true;
for (var i = 0, item = null; item = elmCache.item[i]; i++)
dehighlight(item);
if (childMenuSet) childMenuSet.hide();
slideStart();
_this.ondeactivate();
}
}
function setContainerPos() {
var sub = oActuator.constructor == mtDropDownItem;
var act = sub ? oActuator.parentMenu.elmCache[item][oActuator._index] : oActuator;
var el = act;
var x = 0;
var y = 0;
var minX = 0;
var maxX = (window.innerWidth ? window.innerWidth : document.body.clientWidth) - parseInt(elmCache[clip].style.width);
var minY = 0;
var maxY = (window.innerHeight ? window.innerHeight : document.body.clientHeight) - parseInt(elmCache[clip].style.height);
while (sub ? el.parentNode.className.indexOf(mtDropdownMenu) == -1 : el.offsetParent) {
x += el.offsetLeft;
y += el.offsetTop;
if (el.scrollLeft) x -= el.scrollLeft;
if (el.scrollTop) y -= el.scrollTop;
el = el.offsetParent;
}
if (oActuator.constructor == mtDropDownItem) {
x += parseInt(el.parentNode.style.left);
y += parseInt(el.parentNode.style.top);
}
switch (iReferencePoint) {
case mtDropDown.reference.topLeft:
break;
case mtDropDown.reference.topRight:
x += act.offsetWidth;
break;
case mtDropDown.reference.bottomLeft:
y += act.offsetHeight;
break;
case mtDropDown.reference.bottomRight:
x += act.offsetWidth;
y += act.offsetHeight;
break;
}
x += iLeft;
y += iTop;
x = Math.max(Math.min(x, maxX), minX);
y = Math.max(Math.min(y, maxY), minY);
elmCache[clip].style.left = x + px;
elmCache[clip].style.top = y + px;
}
function slideStart() {
var x0 = parseInt(elmCache[content].style[pos]);
var x1 = _this.isOpen ? 0 : -dim;
if (a != null) a.stop();
a = new Accelimation(x0, x1, mtDropDown.slideTime, slideAccel);
a.onframe = slideFrame;
a.onend = slideEnd;
a.start();
}
function slideFrame(x) {
elmCache[content].style[pos] = x + px;
}
function slideEnd() {
if (!_this.isOpen) elmCache[clip].style.visibility = hidden;
animating = false;
}
function initSize() {
var ow = elmCache[items].offsetWidth;
var oh = elmCache[items].offsetHeight;
var ua = navigator.userAgent.toLowerCase();
elmCache[clip].style.width = ow + mtDropDown.shadowSize + 2 + px;
elmCache[clip].style.height = oh + mtDropDown.shadowSize + 2 + px;
elmCache[content].style.width = ow + mtDropDown.shadowSize + px;
elmCache[content].style.height = oh + mtDropDown.shadowSize + px;
contentHeight = oh + mtDropDown.shadowSize;
contentWidth = ow + mtDropDown.shadowSize;
dim = iDirection == mtDropDown.direction.down ? contentHeight : contentWidth;
elmCache[content].style[pos] = -dim - mtDropDown.shadowSize + px;
elmCache[clip].style.visibility = hidden;
if (ua.indexOf(mac) == -1 || ua.indexOf(gecko) > -1) {
elmCache[background].style.width = ow + px;
elmCache[background].style.height = oh + px;
elmCache[background].style.backgroundColor = mtDropDown.backgroundColor;
elmCache[shadowRight].style.left = ow + px;
elmCache[shadowRight].style.height = oh - (mtDropDown.shadowOffset - mtDropDown.shadowSize) + px;
elmCache[shadowRight].style.backgroundColor = mtDropDown.shadowColor;
elmCache[shadowBottom].style.top = oh + px;
elmCache[shadowBottom].style.width = ow - mtDropDown.shadowOffset + px;
elmCache[shadowBottom].style.backgroundColor = mtDropDown.shadowColor;
}
else {
elmCache[background].firstChild.src = mtDropDown.backgroundPng;
elmCache[background].firstChild.width = ow;
elmCache[background].firstChild.height = oh;
elmCache[shadowRight].firstChild.src = mtDropDown.shadowPng;
更多精彩
赞助商链接