当前位置:编程学习 > JS >>

仿Google首页特效的动感导航菜单

仿Google首页特效的动感导航菜单,这个效果已经很常见了,鼠标放上后图标会变大,移开后恢复原貌,鼠标连续在图标上的滑过,会有更神奇的效果,看上去不错的导航菜单。
答案:<!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>
<title>仿Google首页特效的动感导航菜单</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<style type="text/css">
#fisheye_menu {
	list-style: none;
	padding: 0;
	margin: 10px;
	height: 81px;
}
#fisheye_menu li {
	position: relative;
	display: block;
	float: left;
}
#fisheye_menu span {
	position: absolute;
	top: 100%;
	left: 0;
	text-align: center;
	width: 79px;
	padding: 1px;
	margin: 0;
	border: solid 1px #bbb;	
	color: #333;
	background: #eee;
}
#fisheye_menu a {
	text-decoration: none;
}
#fisheye_menu img {
	border: 0;
	vertical-align: top;
}
</style>
<script type="text/javascript">
var fisheyemenu = {
	startSize : 55,
	endSize : 88,
	imgType : ".gif",
	init : function () {
		var animElements = document.getElementById("fisheye_menu").getElementsByTagName("img");
		var titleElements = document.getElementById("fisheye_menu").getElementsByTagName("span");
		for(var j=0; j<titleElements.length; j++) {
			titleElements[j].style.display = 'none';
		}
		for(var i=0; i<animElements.length; i++) {
			var y = animElements[i];
			y.style.width = fisheyemenu.startSize+'px';
			y.style.height = fisheyemenu.startSize+'px';
			fisheyemenu.imgSmall(y);
			animElements[i].onmouseover = changeSize;
			animElements[i].onmouseout = restoreSize;
		}
		function changeSize() {
			fisheyemenu.imgLarge(this);
			var x = this.parentNode.getElementsByTagName("span");
			x[0].style.display = 'block';
			if (!this.currentWidth) this.currentWidth = fisheyemenu.startSize;
			fisheyemenu.resizeAnimation(this,this.currentWidth,fisheyemenu.endSize,15,10,0.333);
		}
		function restoreSize() {
			var x = this.parentNode.getElementsByTagName("span");
			x[0].style.display = 'none';
			if (!this.currentWidth) return;
			fisheyemenu.resizeAnimation(this,this.currentWidth,fisheyemenu.startSize,15,10,0.5);
			fisheyemenu.imgSmall(this);
		}
	},
	resizeAnimation : function (elem,startWidth,endWidth,steps,intervals,powr) {
		if (elem.widthChangeMemInt) window.clearInterval(elem.widthChangeMemInt);
		var actStep = 0;
		elem.widthChangeMemInt = window.setInterval(
			function() {
				elem.currentWidth = fisheyemenu.easeInOut(startWidth,endWidth,steps,actStep,powr);
				elem.style.width = elem.currentWidth+"px";
				elem.style.height = elem.currentWidth+"px";
				actStep++;
				if (actStep > steps) window.clearInterval(elem.widthChangeMemInt);
			}
			,intervals)
	},
	easeInOut : function (minValue,maxValue,totalSteps,actualStep,powr) {
		var delta = maxValue - minValue;
		var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
		return Math.ceil(stepp)
	},
	imgSmall : function (obj) {
		imgSrc = obj.getAttribute("src");
		var typePos = imgSrc.indexOf(fisheyemenu.imgType, 0);
		var imgName = imgSrc.substr(0, typePos);
		obj.setAttribute("src", imgName+"_small"+fisheyemenu.imgType);
	},
	imgLarge : function (obj) {
		imgSrc = obj.getAttribute("src");
		var typePos = imgSrc.indexOf("_small", 0);
		var imgName = imgSrc.substr(0, typePos);
		obj.setAttribute("src", imgName+fisheyemenu.imgType);
	}
}
if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fisheyemenu.init, false );
else if ( typeof window.attachEvent != "undefined" )
    window.attachEvent( "onload", fisheyemenu.init );
else {
    if ( window.onload != null ) {
        var oldOnload = window.onload;
        window.onload = function ( e ) {
            oldOnload( e );
            fisheyemenu.init();
        };
    }
    else
        window.onload = fisheyemenu.init;
}
</script>
</head>
<body>
<div>
	<ul id="fisheye_menu">
		<li><a href="#"><img src="/jscss/demoimg/201010/icon1.gif" alt="1"><span>图片搜索</span></a></li>
		<li><a href="#"><img src="/jscss/demoimg/201010/icon2.gif" alt="2"><span>高级搜索</span></a></li>
		<li><a href="#"><img src="/jscss/demoimg/201010/icon1.gif" alt="3"><span>Google地图</span></a></li>
	</ul>
</div>
</body>
</html>

上一个:jQuery TAB淡入淡出的选项卡菜单
下一个:myFocus-tab 各种功能的选项卡切换

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,