实例介绍
【实例简介】
【实例截图】
【核心代码】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> < html > < head > < title >Little Boxes Menu with jQuery</ title > < meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8" /> < meta name = "description" content = "Little Boxes Menu or Navigation with jQuery - radnomly animate the menu items to show content, accodion like boxes menu" /> < meta name = "keywords" content = "jquery, boxes, menu, navigation, animate" /> < link rel = "stylesheet" href = "css/style.css" type = "text/css" media = "screen" /> < style > *{ margin:0; padding:0; } body{ background:#E4FFCF url(wood.jpg) no-repeat top center; font-family:Futura, "Century Gothic", AppleGothic, sans-serif; overflow:hidden; } h1{ color:#fff; margin:40px 0px 20px 40px; text-shadow:1px 1px 1px #555; font-weight:normal; } a.back{ position:absolute; bottom:5px; right:5px; } .reference{ position:absolute; bottom:5px; left:5px; } .reference p a, a.back{ text-transform:uppercase; text-shadow:1px 1px 1px #fff; color:#666; text-decoration:none; font-size:16px; font-weight:bold; } .reference p a:hover, a.back:hover{ color:#000; } </ style > </ head > < body > < div class = "title" > < h1 >Little Boxes Menu with jQuery</ h1 > </ div > < div id = "content" > < div class = "reference" > < p >< a href = "http://www.flickr.com/photos/adforce1/" >Photos from williamcho's photostream on Flickr</ a ></ p > </ div > < a class = "back" href = "http://tympanus.net/codrops/2010/05/18/little-boxes-menu-with-jquery" >Back to Codrops</ a > < div id = "littleBoxes" class = "littleBoxes" > < div class = "boxlink bg1" style = "top:0px;left:0px;" > < a href = "" >About</ a > < div class = "boxcontent" > < p >Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </ p > </ div > </ div > < div class = "bg5" style = "background-position:-90px 0;top:0px;left:95px;" ></ div > < div class = "bg5" style = "background-position:-180px 0;top:0px;left:190px;" ></ div > < div class = "bg5" style = "background-position:-270px 0;top:0px;left:285px;" ></ div > < div class = "bg5" style = "background-position:0 -90px;top:95px;left:0px;" ></ div > < div class = "boxlink bg2" style = "top:95px;left:95px;" > < a href = "" >Menu</ a > < div class = "boxcontent" > < p >Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </ p > </ div > </ div > < div class = "bg5" style = "background-position:-180px -90px;top:95px;left:190px;" ></ div > < div class = "bg5" style = "background-position:-270px -90px;top:95px;left:285px;" ></ div > < div class = "bg5" style = "background-position:0 -180px;top:190px;left:0px;" ></ div > < div class = "bg5" style = "background-position:-90px -180px;top:190px;left:95px;" ></ div > < div class = "boxlink bg3" style = "top:190px;left:190px;" > < a href = "" >Chef</ a > < div class = "boxcontent" > < p >Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </ p > </ div > </ div > < div class = "bg5" style = "background-position:-270px -180px;top:190px;left:285px;" ></ div > < div class = "bg5" style = "background-position:0 -270px;top:285px;left:0px;" ></ div > < div class = "bg5" style = "background-position:-90px -270px;top:285px;left:95px;" ></ div > < div class = "bg5" style = "background-position:-180px -270px;top:285px;left:190px;" ></ div > < div class = "boxlink bg4" style = "top:285px;left:285px;" > < a href = "" >Contact</ a > < div class = "boxcontent" > < p >Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </ p > </ div > </ div > </ div > </ div > <!-- The JavaScript --> < script type = "text/javascript" src = "jquery.easing.1.3.js" ></ script > < script type = "text/javascript" > $(function() { /* object to save the initial positions of each box */ var divinfo = {"initial": []}; /* index of the selected / clicked box */ var current = -1; /* we save the index,top and left of each one of the boxes */ $('#littleBoxes > div').each(function(){ var $this = $(this); var initial = { 'index' : $this.index(), 'top' : $this.css('top'), 'left' : $this.css('left') }; divinfo.initial.push(initial); }); /* clcik event for the anchors inside of the boxes */ $('#littleBoxes a').bind('click',function(e){ var $this = $(this); var $currentBox = $this.parent(); /* set a z-index lower than all the other boxes, to see the other boxes animation on the top*/ $currentBox.css('z-index','1'); /* if we are clicking on a expanded box : */ if(current == $currentBox.index()){ /* put it back (decrease width,height, and set the top and left like it was before). the previous positions are saved in the divinfo obj*/ $currentBox.stop().animate({ 'top' : divinfo.initial[$currentBox.index()].top, 'left' : divinfo.initial[$currentBox.index()].left, 'width' : '90px', 'height' : '90px' },800,'easeOutBack').find('.boxcontent').fadeOut(); $('#littleBoxes > div').not($currentBox).each(function(){ var $ele = $(this); var elemTop = divinfo.initial[$ele.index()].top; var elemLeft = divinfo.initial[$ele.index()].left; $ele.stop().show().animate({ 'top' : elemTop, 'left' : elemLeft, 'opacity' : 1 },800); }); current = -1; } /* if we are clicking on a small box : */ else{ /* randomly animate all the other boxes. Math.floor(Math.random()*601) - 150 gives a random number between -150 and 450. This range is considering the initial lefts/tops of the elements. It's not the exact right range, since we would have to calculate the range based on each one of the boxes. Anyway, it fits our needs... */ $('#littleBoxes > div').not($currentBox).each(function(){ var $ele = $(this); $ele.stop().animate({ 'top' : (Math.floor(Math.random()*601) - 150) 'px', 'left': (Math.floor(Math.random()*601) - 150) 'px', 'opacity':0 },800,function(){ $(this).hide(); }); }); /* expand the clicked one. Also, fadeIn the content (boxcontent) if you want it to fill the space of the littleBoxes container, then these are the right values */ var newwidth = 379; var newheight = 379; $currentBox.stop().animate({ 'top' : '0px', 'left' : '0px', 'width' : newwidth 'px', 'height': newheight 'px' },800,'easeOutBack',function(){ current = $currentBox.index(); $(this).find('.boxcontent').fadeIn(); }); } e.preventDefault(); }); }); </ script > </ body > </ html > |
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论