WEB开发网
开发学院网页设计JavaScript 玩转动感滑动透明菜单(一) 阅读

玩转动感滑动透明菜单(一)

 2007-11-27 16:10:53 来源:WEB开发网   
核心提示:<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN><HTML><HEAD><TITLE>玩转动感滑动透明菜单(一)</TITLE><!-- Make By CSDN Nba23 8/6

<!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;

Tags:动感 滑动 透明

编辑录入:coldstar [复制链接] [打 印]
赞助商链接