1/** 2 * jquery.easymenu.js 3 * è¿ä¸ªä¸ä¸ªjQueryçæä»¶ï¼å®å¯ä»¥è®©æ¨åå»ºä¸æè¯ç导èªèåæ´å ç®åã 4 * 5 * -- REQUIRE: jQuery 1.4+ -- 6 * 7 * @author Hpyer 8 * @home http://hpyer.cn 9 * @version 1.0.2 10 * @release 2014-01-03 11 */ 12 13/* 14USAGE: 15 16<html> 17<head> 18<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> 19<link rel="stylesheet" type="text/css" href="jquery.easymenu.css" /> 20<script type="text/javascript" src="jquery.easymenu.js"></script> 21</head> 22<body> 23<ul id="menu" class="clearfix"> 24 <li><a href="#">Home</a></li> 25 <li><a href="#">Tutorials</a> 26 <ul> 27 <li><a href="#">2nd Nav Link</a> 28 <ul> 29 <li><a href="#">3rd Nav Link</a></li> 30 <li><a href="#">3rd Nav Link</a></li> 31 </ul> 32 </li> 33 <li><a href="#">2nd Nav Link</a></li> 34 </ul> 35 </li> 36</ul> 37<script>$('#menu').easymenu();</script> 38</body> 39</html> 40*/ 41 42(function($) { 43 $.fn.easymenu = function(options) { 44 var default_options = { 45 'hover_class' : 'hover', // é¼ æ è¿è¿èå项æ¶çclass 46 'main_item_class' : 'main-item', // 主èå项çclass 47 'sub_item_class' : 'sub-item', // åèå项çclass 48 'separator_class' : 'separator', // åé符çclass 49 'has_child_class' : 'has-child' // 嫿åèåæ¶çclass 50 }; 51 options = $.extend(default_options, options); 52 53 this.each(function(i, item) { 54 55 // åºå主èå项ååèå项 56 $(item).children('li').addClass(options.main_item_class).find('li').addClass(options.sub_item_class); 57 58 $(item) 59 // 夿åèå项类å 60 .find('li').each(function(j, li) { 61 // ç»ç©ºçèå项添å separatorç±» 62 if ($(li).html() == '') $(li).removeClass().addClass(options.separator_class); 63 // 妿æåèåï¼åæ·»å has_childç±» 64 if ($(li).children('ul').length > 0) $(li).addClass(options.has_child_class); 65 }) 66 67 // èåäºä»¶å¤ç 68 .hover(function() { 69 // 䏿¯åéç¬¦åæ·»å hoverç±» 70 if (!$(this).hasClass(options.separator_class)) $(this).addClass(options.hover_class); 71 72 // æåèåï¼åæ¾ç¤º 73 if ($(this).hasClass(options.has_child_class)) { 74 var submenu = $(this).children('ul'); 75 var is_first_submenu = $(this).hasClass(options.main_item_class); 76 var p_pos = $(this).position(); // å½åèå项ä½ç½® 77 var p_w = parseInt($(this).outerWidth()); // å½åèå项宽 78 var p_h = parseInt($(this).outerHeight()); // å½åèåé¡¹é« 79 var w = parseInt(submenu.outerWidth()); // å½ååèå宽 80 var h = parseInt(submenu.outerHeight()); // å½ååèåé« 81 82 // åºåå¤çä¸çº§åèåçä½ç½® 83 var css = {}; 84 var p_offset = $(this).offset(); // å½åèåçä½ç½® 85 if (is_first_submenu) { 86 css.left = parseInt(p_pos.left); 87 css.top = parseInt(p_pos.top) + p_h; 88 // å¦æè¶ åºå±å¹ï¼åå°ä¸çº§åèåçleft-å½ååèå宽+å½åèå项宽+1 89 if ((p_offset.left + w) > $(document).width()) css.left = css.left - w + p_w + 1; 90 } else { 91 css.left = parseInt(p_pos.left) + p_w - 1; 92 css.top = parseInt(p_pos.top); 93 // å¦æè¶ åºå±å¹ï¼åå°åèåçleft-å½ååèå宽-å½åèå项宽+1 94 if ((p_offset.left + p_w + w) >
94 $(document).width()) css.left = css.left - w - p_w + 1; 95 } 96 97 // æ¾ç¤ºåèå 98 submenu.css(css).show(); 99 } 100 }, function() { 101 // 䏿¯åé符åç§»é¤hoverç±» 102 if (!$(this).hasClass(options.separator_class)) $(this).removeClass(options.hover_class); 103 104 // æåèåï¼åéè 105 if ($(this).hasClass(options.has_child_class)) { 106 var submenu = $(this).children('ul'); 107 submenu.hide(); 108 } 109 }); 110 }); 111 } 112})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.