{"id":1214,"date":"2010-10-28T14:43:27","date_gmt":"2010-10-28T13:43:27","guid":{"rendered":"http:\/\/www.simonbattersby.com\/blog\/?page_id=1214"},"modified":"2013-07-18T14:09:41","modified_gmt":"2013-07-18T13:09:41","slug":"jquery-dropdown-menu-plugin-with-css-fallback","status":"publish","type":"page","link":"https:\/\/www.simonbattersby.com\/blog\/jquery-dropdown-menu-plugin-with-css-fallback\/","title":{"rendered":"jQuery dropdown menu plugin with css fallback"},"content":{"rendered":"<p>Partly as an exercise in writing a jQuery plugin, I&#8217;ve created a configurable jQuery dropdown menu. In the absence of javascript, the menu reverts to a standard css dropdown menu. It&#8217;s based on my original css dropdown menu <a href=\"\/blog\/css-horizontal-menu-with-dropdowns\/\" title=\"Dropdown menu css only\">here<\/a>. My thinking was to allow the simple use of a few nice jQuery animations without compromising the experience for anyone without javascript.<\/p> \r\n\r\n<p>View a demo <a href=\"\/demos\/menuplugin_demo.htm\" title=\"jQuery menu demo\">here<\/a>, which illustrates two menus with different options selected, plus another running on css only. Have a look at option 4.3 and option 4.3.1 to see the third and fourth level menus.<\/p>\r\n\r\n<p>I&#8217;ve tested in FF3, IE8, IE7, IE6, Opera 9, Opera 10, Safari 4, Safari 5 and Chrome, on Win\/XP, and FF15, Opera 12, IE7, IE and IE9 on Windows 7. If you&#8217;re (still) using IE6, then this will work for two level menus but no more&#8230;<\/p>\r\n\r\n<h3>Setup<\/h3>\r\n\r\n<p>This menu requires jQuery, so you need to load this and the plugin into in your head, plus the css file:<\/p>\r\n\r\n<pre>&lt;script type=\"text\/javascript\" src=\"http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.4.3\/jquery.min.js\"&gt;&lt;\/script&gt;\r\n&lt;script type=\"text\/javascript\" src=\"\/javascript\/jquery.orangemenu.js\"&gt;&lt;\/script&gt;\r\n&lt;link rel=\"stylesheet\" href=\"\/css\/orangemenu.css\"\/&gt;\r\n<\/pre>\r\n\r\n<p>The plugin expects html in the form of a nested unordered list like this:<\/p>\r\n\r\n<pre>&lt;ul class=\"orangemenu\" id=\"mymenu\"&gt;\r\n&lt;li&gt;&lt;a href=\"#\"&gt;Item 1&lt;\/a&gt;\r\n     &lt;ul&gt;\r\n     &lt;li&gt;&lt;a href=\"#\"&gt;Item 1.1&lt;\/a&gt;&lt;\/li&gt;\r\n     &lt;\/ul&gt;\r\n&lt;\/li&gt;\r\n&lt;li&gt;&lt;a href=\"#\"&gt;Item 2&lt;\/a&gt;\r\n     &lt;ul&gt;\r\n     &lt;li&gt;&lt;a href=\"#\"&gt;Item 2.1&lt;\/a&gt;&lt;\/li&gt;\r\n     &lt;li&gt;&lt;a href=\"#\"&gt;Item 2.2&lt;\/a&gt;\r\n\t \t&lt;ul&gt;\r\n\t\t\t &lt;li&gt;&lt;a href=\"#\"&gt;Item 2.2.1&lt;\/a&gt;&lt;\/li&gt;\r\n\t\t\t &lt;li&gt;&lt;a href=\"#\"&gt;Item 2.2.2&lt;\/a&gt;&lt;\/li&gt;\r\n\t\t&lt;\/ul&gt;\r\n\t &lt;\/li&gt;\r\n     &lt;\/ul&gt;\r\n&lt;\/li&gt;\r\n&lt;\/ul&gt;<\/pre>\r\n\r\n<p>Give the menu any id you want, but make sure it has the orangemenu class otherwise it won&#8217;t work. Right, now we&#8217;ve got the plugin, some css and some html we&#8217;re ready to go.<\/p>\r\n\r\n<h3>Configuration<\/h3>\r\n\r\n<p>To use the plugin with default settings all you need is this:<\/p>\r\n\r\n<pre>&lt;script type=&quot;text\/javascript&quot;&gt;\r\n$(document).ready(function(){\r\n$('#mymenu').orangemenu();\r\n});\r\n&lt;\/script&gt;<\/pre>\r\n\r\n<h4>Animation effect options<\/h4>\r\n<ul class=\"bulletlist\">\r\n<li><strong>&#8216;fade&#8217;<\/strong> &#8211; submenus fade in and out &#8211; this is the default effect<\/li>\r\n<li><strong>&#8216;slide&#8217;<\/strong> &#8211; submenus slide down and up<\/li>\r\n<li><strong>&#8216;diagonal&#8217;<\/strong> &#8211; submenus expand top left to bottom right<\/li>\r\n<li><strong>&#8216;left&#8217;<\/strong> &#8211; submenus slide across from left to right<\/li>\r\n<li><strong>&#8216;slidefade&#8217;<\/strong> &#8211; combines the &#8216;slide&#8217; and &#8216;fade&#8217; effects<\/li>\r\n<li><strong>&#8216;diagonalfade&#8217;<\/strong> &#8211; combines the &#8216;diagonal&#8217; and &#8216;fade&#8217; effects<\/li>\r\n<li><strong>&#8216;show&#8217;<\/strong> &#8211; submenus appear and disappear &#8211; this is identical to the default css behaviour but is included for completeness. It also works in IE6, unlike the basic css.<\/li>\r\n<\/ul>\r\n\r\n<h4>Animation duration options<\/h4>\r\n<ul class=\"bulletlist\">\r\n<li><strong>&#8216;slow&#8217;<\/strong> &#8211; 600ms<\/li>\r\n<li><strong>&#8216;fast&#8217;<\/strong> &#8211; 200ms<\/li>\r\n<li><strong>1000<\/strong> &#8211; 1000ms &#8211; or <strong>any numeric duration<\/strong> in milliseconds<\/li>\r\n<\/ul>\r\n\r\n<h4>Configuration examples<\/h4>\r\n<p>This sets an effect of &#8216;diagonal&#8217; with 600ms duration.<\/p>\r\n<pre>$(document).ready(function(){\r\n    $('#mymenu').orangemenu({duration: 'slow',effect: 'diagonal'});\r\n});<\/pre>\r\n\r\n<p>This sets an effect of &#8216;slide&#8217; with 1000ms duration.<\/p>\r\n<pre>$(document).ready(function(){\r\n    $('#mymenu').orangemenu({duration: 1000,effect: 'slide'});\r\n});<\/pre>\r\n\r\n<h3>Configuring multiple menus on a page<\/h3>\r\n<p>You probably won&#8217;t want this, but the plugin supports multiple usage on a page with different options on each menu. You just need to ensure that each menu has a separate id:<\/p>\r\n\r\n<pre>$(document).ready(function(){\r\n    $('#mymenu').orangemenu({duration: 'slow',effect: 'diagonal'});\r\n    $('#mymenu2').orangemenu({duration: 'slow',effect: 'slide'});\r\n});<\/pre>\r\n\r\n<h3>Download<\/h3>\r\n<p><a href='\/demos\/downloads\/orangemenu.zip'>Orangemenu zip file<\/a> (2kb)<\/p>\r\n<h3>Can I use this on my site?<\/h3>\r\n<p>Probably. See my <a href=\"\/blog\/use-of-code-from-this-site\/\">policies on using code from this site<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Partly as an exercise in writing a jQuery plugin, I&#8217;ve created a configurable jQuery dropdown menu. In the absence of javascript, the menu reverts to a standard css dropdown menu. It&#8217;s based on my original css dropdown menu here. My thinking was to allow the simple use of a few nice jQuery animations without compromising [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1214","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/pages\/1214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/comments?post=1214"}],"version-history":[{"count":6,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/pages\/1214\/revisions"}],"predecessor-version":[{"id":2866,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/pages\/1214\/revisions\/2866"}],"wp:attachment":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/media?parent=1214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}