本文实例讲述了JS实现Fisheye效果动感放大菜单代码。分享给大家供大家参考,具体如下:
这款Fisheye Menu,是采用JS+CSS+XHTML实现的动感放大菜单,放到图标上的时候,图标会被放大,整个菜单有缓冲弹簧的效果,学jQuery的朋友见的比较多,不过本款没有用到jQuery,效果却同样精彩。
运行效果截图如下:
在线演示地址如下:
http://demo.jb51.net/js/2015/js-fisheye-style-menu-demo/
具体代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/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; 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="#1"><img src="/UploadFiles/2021-04-02/icon.gif">希望本文所述对大家JavaScript程序设计有所帮助。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年11月20日
2024年11月20日
- 谭嘉仪-EyesOnMe新曲+精选2022【低速原抓WAV+CUE】
- 尚士达《莫回头》[320K/MP3][184.64MB]
- 尚士达《莫回头》[Hi-Res][24bit 48kHz][FLAC/分轨][1.27G]
- 群星《奔赴!万人现场 第3期》[320K/MP3][98.9MB]
- 谭嘉仪《Lonely》【WAV+CUE】
- 群星《红色钢琴浪漫曲》2CD【WAV+CUE】
- 凤飞飞《浮世情怀》HQCD[正版原抓WAV+CUE]
- 群星《奔赴!万人现场 第3期》[FLAC/分轨][537.75MB]
- 群星 《2024好听新歌23》十倍音质 U盘音乐 [WAV分轨][1.6G]
- 群星《妙音纪念珍藏版》蓝光BSCD[WAV+CUE][1G]
- 【发烧试音】蔡克信严讯人间天籁》[原抓WAV+CUE]
- [ABC唱片]山姆泰勒《西电之声·萨克斯风》[低速原抓WAV+CUE]
- 童丽《微风细雨XRCD2》[原抓WAV+CUE]
- 群星 《车乐坊1》DTS魔音[WAV+CUE][1.7G]
- 邓丽君.2024 -《生誕70年ベスト?アルバム 沒後30年》环球日版 [WAV+分轨][993M]