JS实现Fisheye效果动感放大菜单代码
网络编程 2021-07-04 21:03www.168986.cn编程入门
这篇文章主要介绍了JS实现Fisheye效果动感放大菜单代码,涉及JavaScript事假监听机制及定时函数等相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了JS实现Fisheye效果动感放大菜单代码。分享给大家供大家参考,具体如下
这款Fisheye Menu,是采用JS+CSS+XHTML实现的动感放大菜单,放到图标上的时候,图标会被放大,整个菜单有缓冲弹簧的效果,学jQuery的朋友见的比较多,不过本款没有用到jQuery,效果却同样精彩。
运行效果截图如下
在线演示地址如下
具体代码如下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://.w3./TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://.w3./1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Fisheye 动感放大的菜单</title> <style> #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; : 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: ; } </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="#1"><img src="images/icon.gif" alt="狼蚁SEO" /><span>Icon 1</span></a></li> <li><a href="#2"><img src="images/icon2.gif" alt="image description" /><span>Icon 2</span></a></li> <li><a href="#3"><img src="images/icon.gif" alt="脚本下载" /><span>Icon 3</span></a></li> <li><a href="#4"><img src="images/icon2.gif" alt="image description" /><span>Icon 4</span></a></li> <li><a href="#5"><img src="images/icon.gif" alt="jb51." /><span>Icon 5</span></a></li> <li><a href="#6"><img src="images/icon2.gif" alt="image description" /><span>Icon 6</span></a></li> </ul> </div> </body> </html>
希望本文所述对大家JavaScript程序设计有所帮助。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程