Revision 308 is a pre-publication revision. (Viewing current revision instead.)

Auto Draft

Taken from Studio Nashvegas: http://www.studionashvegas.com/responsive-design-2/a-responsive-menu-solution-for-wordpress/ Here is a working example of the responsive select menu: http://www.outandaboutmarketing.com/ A few months ago I modified a really cool WordPress template and started using it for my own clients.  As part of the overhaul, I realized that there was no really good way (included) to turn a WordPress unordered list into a menu that would work on a mobile device.  I tried a few different solutions, but in the end went for the simple one.  A selection (drop-down) menu works well, allows for an infinite number of parent and child categories, and is easily done with a simple jQuery script. I’ve since modified that script, and wanted to share it as a snippit with you.  Make sure you have jQuery loaded somewhere before this script: [php]<script> // Create the dropdown base $(".menu-main-container li a").addClass("top-level"); $(".menu-main-container .sub-menu li a").addClass("second-level"); $("<select class='main-drop' />").appendTo(".menu-main-container"); // Create default option "Go to..." $("<option />", { "selected": "selected", "value" : "", "text" : "Main Navigation" }).appendTo(".menu-main-container select"); // Populate dropdown with menu items $(".menu-main-container li a").each(function() { var el = $(this); $("<option />", { "value" : el.attr("href"), "text" : el.text(), "class" : el.attr("class") }).appendTo(".menu-main-container select"); }); // Allows user to automatically "submit" selection and travel to page $(".menu-main-container select").change(function() { window.location = $(this).find("option:selected").val(); }); // adds a dash to second-level classes $('<p>- </p>').prependTo('option.second-level'); </script>[/php] Here is some css: [css].main-drop{ display: none; } /* All Mobile Sizes (devices and browser) */ @media only screen and (max-width: 767px) { .main-drop{ display: block; width: 94%; margin: 10px 3% 10px; } }[/css]

Revisions

Revision Differences

November 27, 2012 @ 01:15:41Current Revision
Title
Deleted: Auto DraftAdded: Responsive WordPress Menus
Content
 Added: Taken from Studio Nashvegas: <a href="http:// www.studionashvegas.com/responsive- design-2/a-responsive-menu- solution-for-wordpress/" target="_blank" >http://www.studionashvegas.com/ responsive-design- 2/a-responsive- menu-solution- for-wordpress/</a>
 Added: Here is a working example of the responsive select menu: <a href="http:// www.outandaboutmarketing.com/" target="_blank" >http://www.outandaboutmarketing.com/</a>
 Added: A few months ago I modified a really cool WordPress template and started using it for my own clients.  As part of the overhaul, I realized that there was no really good way (included) to turn a WordPress unordered list into a menu that would work on a mobile device.  I tried a few different solutions, but in the end went for the simple one.  A selection (drop-down) menu works well, allows for an infinite number of parent and child categories, and is easily done with a simple jQuery script.
 Added: I’ve since modified that script, and wanted to share it as a snippit with you.  Make sure you have jQuery loaded somewhere before this script:
 Added: [php]&lt;script&gt;
 Added: // Create the dropdown base
 Added: $(&quot;.menu- main-container li a&quot;).addClass( &quot;top-level&quot;);
 Added: $(&quot;.menu- main-container .sub-menu li a&quot;).addClass( &quot;second- level&quot;);
 Added: $(&quot;&lt;select class='main-drop' /&gt;&quot;).appendTo( &quot;.menu-main- container&quot;);
 Added: // Create default option &quot;Go to...&quot;
 Added: $(&quot;&lt;option /&gt;&quot;, {
 Added: &quot;selected&quot;: &quot;selected&quot;,
 Added: &quot;value&quot; : &quot;&quot;,
 Added: &quot;text&quot; : &quot;Main Navigation&quot;
 Added: }).appendTo(&quot; .menu-main-container select&quot;);
 Added: // Populate dropdown with menu items
 Added: $(&quot;.menu- main-container li a&quot;).each(function() {
 Added: var el = $(this);
 Added: $(&quot;&lt;option /&gt;&quot;, {
 Added: &quot;value&quot; : el.attr(&quot; href&quot;),
 Added: &quot;text&quot; : el.text(),
 Added: &quot;class&quot; : el.attr(&quot; class&quot;)
 Added: }).appendTo(&quot; .menu-main-container select&quot;);
 Added: });
 Added: // Allows user to automatically &quot;submit&quot; selection and travel to page
 Added: $(&quot;.menu- main-container select&quot;) .change(function() {
 Added: window.location = $(this).find( &quot;option: selected&quot;).val();
 Added: });
 Added: // adds a dash to second-level classes
 Added: $('&lt;p&gt;- &lt;/p&gt;').prependTo( 'option.second-level');
 Added: &lt;/script&gt;[/php]
 Added: Here is some css:
 Added: [css].main-drop{
 Added: display: none;
Deleted: Added: }
 Added: /* All Mobile Sizes (devices and browser) */
 Added: @media only screen and (max-width: 767px) {
 Added: .main-drop{
 Added: display: block;
 Added: width: 94%;
 Added: margin: 10px 3% 10px;
 Added: }
 Added: }[/css]

Note: Spaces may be added to comparison text to allow better line wrapping.

Tags: , ,

No comments yet.

Leave a Reply