JS實(shí)現(xiàn)Fisheye效果動(dòng)感放大菜單代碼
本文實(shí)例講述了JS實(shí)現(xiàn)Fisheye效果動(dòng)感放大菜單代碼。分享給大家供大家參考,具體如下:
這款Fisheye Menu,是采用JS+CSS+XHTML實(shí)現(xiàn)的動(dòng)感放大菜單,放到圖標(biāo)上的時(shí)候,圖標(biāo)會(huì)被放大,整個(gè)菜單有緩沖彈簧的效果,學(xué)jQuery的朋友見(jiàn)的比較多,不過(guò)本款沒(méi)有用到j(luò)Query,效果卻同樣精彩。
運(yùn)行效果截圖如下:
在線演示地址如下:
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 動(dòng)感放大的菜單</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="images/icon.gif" alt="腳本之家" /><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.net" /><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>
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。
- JS+CSS實(shí)現(xiàn)大氣清新的滑動(dòng)菜單效果代碼
- JS實(shí)現(xiàn)的豎向折疊菜單代碼
- JS基于Mootools實(shí)現(xiàn)的個(gè)性菜單效果代碼
- JS+CSS實(shí)現(xiàn)的經(jīng)典圓角下拉菜單效果代碼
- JS+CSS實(shí)現(xiàn)另類帶提示效果的豎向?qū)Ш讲藛?/a>
- JS實(shí)現(xiàn)的簡(jiǎn)潔二級(jí)導(dǎo)航菜單雛形效果
- JS實(shí)現(xiàn)帶圓弧背景漸變效果的導(dǎo)航菜單代碼
- JS實(shí)現(xiàn)的仿東京商城菜單、仿Win右鍵菜單及仿淘寶TAB特效合集
- JS實(shí)現(xiàn)淘寶支付寶網(wǎng)站的控制臺(tái)菜單效果
- JS實(shí)現(xiàn)仿QQ效果的三級(jí)豎向菜單
- JS實(shí)現(xiàn)新浪博客左側(cè)的Blog管理菜單效果代碼
相關(guān)文章
微信小程序Page中data數(shù)據(jù)操作和函數(shù)調(diào)用方法
這篇文章主要介紹了微信小程序Page中data數(shù)據(jù)操作和函數(shù)調(diào)用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05javascript實(shí)現(xiàn)在網(wǎng)頁(yè)中運(yùn)行本地程序的方法
這篇文章主要介紹了javascript實(shí)現(xiàn)在網(wǎng)頁(yè)中運(yùn)行本地程序的方法,實(shí)例分析了JavaScript基于ActiveXObject運(yùn)行本地程序的技巧,需要的朋友可以參考下2016-02-02純JavaScript 實(shí)現(xiàn)flappy bird小游戲?qū)嵗a
這篇文章主要介紹了純JavaScript 實(shí)現(xiàn)flappy bird小游戲?qū)嵗a,b本文分七大步驟給大家介紹,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09關(guān)于javascript解決閉包漏洞的一個(gè)問(wèn)題詳解
閉包在JavaScript高級(jí)程序設(shè)計(jì)(第3版)中是這樣描述:閉包是指有權(quán)訪問(wèn)另一個(gè)函數(shù)作用域中的變量的函數(shù),下面這篇文章主要給大家介紹了關(guān)于javascript解決閉包漏洞的一個(gè)問(wèn)題的相關(guān)資料,需要的朋友可以參考下2022-11-11JavaScript實(shí)現(xiàn)異步獲取表單數(shù)據(jù)
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)異步獲取表單數(shù)據(jù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-05-05js中substring和substr的詳細(xì)介紹與用法
這篇文章介紹了js中substring和substr的用法,有需要的朋友可以參考一下2013-08-08