<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>navigation Archives - Michael Sunarlim</title>
	<atom:link href="https://sunarlim.com/tag/navigation/feed/" rel="self" type="application/rss+xml" />
	<link>https://sunarlim.com/tag/navigation/</link>
	<description>Random blurbs about web development, e-commerce and technology</description>
	<lastBuildDate>Sun, 24 Jan 2016 05:33:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.5</generator>

<image>
	<url>https://i0.wp.com/sunarlim.com/wp-content/uploads/2016/07/cropped-MS_Square_512x512.png?fit=32%2C32&#038;ssl=1</url>
	<title>navigation Archives - Michael Sunarlim</title>
	<link>https://sunarlim.com/tag/navigation/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">30613895</site>	<item>
		<title>Responsive Multi-level Menu to Dropdown</title>
		<link>https://sunarlim.com/2013/02/responsive-multi-level-menu-to-dropdown/</link>
					<comments>https://sunarlim.com/2013/02/responsive-multi-level-menu-to-dropdown/#respond</comments>
		
		<dc:creator><![CDATA[Michael]]></dc:creator>
		<pubDate>Wed, 27 Feb 2013 07:45:30 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[responsive]]></category>
		<guid isPermaLink="false">https://sunarlim.com/?p=728</guid>

					<description><![CDATA[<p>Thanks to this excellent tutorial from CSS-Tricks explaining how to create list-based menu into select dropdown on small screens, I was able to finally complete the product detail pages on Bluelounge website. My homework was not finished though. With around 20 active products on the website, I needed to preserve the product categories within the... <span class="more"><a class="more-link" href="https://sunarlim.com/2013/02/responsive-multi-level-menu-to-dropdown/">Continue reading <span class="meta-nav">&#8594;</span></a></span></p>
<p>The post <a href="https://sunarlim.com/2013/02/responsive-multi-level-menu-to-dropdown/">Responsive Multi-level Menu to Dropdown</a> appeared first on <a href="https://sunarlim.com">Michael Sunarlim</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Thanks to <a href="http://css-tricks.com/convert-menu-to-dropdown/" target="_blank">this excellent tutorial from CSS-Tricks</a> explaining how to create list-based menu into select dropdown on small screens, I was able to finally complete the product detail pages on <a href="http://www.bluelounge.com/" target="_blank">Bluelounge website</a>. My homework was not finished though. With around 20 active products on the website, I needed to preserve the product categories within the dropdown menu to make it easier for visitors to check out other products. With some adjustments and a few extra lines of codes, it now works the way I wanted.<br />
<span id="more-728"></span></p>
<h3>Reading Requirement</h3>
<p>Before I begin, please first read the tutorial from CSS-Tricks to understand the initial concept: <a href="http://css-tricks.com/convert-menu-to-dropdown/" target="_blank">Convert a Menu to a Dropdown for Small Screens</a></p>
<h3>The HTML</h3>
<p>Here is the simplified HTML I use for the navigation:</p>
<pre class="lang:default decode:true ">&lt;ul id="list-products"&gt;
&lt;li class="category"&gt;&lt;h3&gt;Cable Management&lt;/h3&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/products/sumo/"&gt;Sumo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/products/cableboxmini/"&gt;CableBox Mini&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/products/cableclip/" &gt;CableClip&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/products/cabledrop/"&gt;CableDrop&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/products/cablebox/"&gt;CableBox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/products/cableyoyo/"&gt;Cableyoyo&lt;/a&gt;&lt;/li&gt;
&lt;li class="category"&gt;&lt;h3&gt;Stands&lt;/h3&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/products/mika/"&gt;Mika&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/products/milo/"&gt;Milo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/products/nest/"&gt;Nest&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/products/notebookkit/"&gt;Notebook Kit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/products/coolfeet/"&gt;Cool Feet&lt;/a&gt;&lt;/li&gt;
&lt;li class="category"&gt;&lt;h3&gt;Chargers&lt;/h3&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/products/minidock/"&gt;MiniDock&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/products/refresh/"&gt;Refresh&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/products/extraconnectors/"&gt;Extra Connectors&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/products/thesanctuary/"&gt;The Sanctuary&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</pre>
<p>I use <span class="lang:default decode:true crayon-inline ">class=&#8221;category&#8221;</span>  and <span class="lang:default decode:true crayon-inline ">&lt;h3&gt;&lt;/h3&gt;</span>  for list items that are categories. Since we do not have a category page, the list items do not have a link.</p>
<h3>jQuery</h3>
<p>The fun part was to modify the original code to only create dropdown options from list items with <code>class="category"</code> and then list the following option with the URL as value until it finds the next category title.<br />
Another code I added was to validate when changed if it has a (URL) value, otherwise it will not change the page.</p>
<pre class="lang:default decode:true">// Create the dropdown base
$("&lt;select /&gt;").appendTo(".productlist ");

// Create default option "Products."
$("&lt;option /&gt;", {
"selected": "selected",
"value" : "",
"text" : "Products"
}).appendTo(".productlist select");

// Populate dropdown with menu items
$(".productlist .category").each(function() { // List category titles
var el = $(this);
$("&lt;option /&gt;", {
"text" : el.text(),
"class" : "category" // Add class to the menu item
}).appendTo(".productlist select");
// Look for next items until there it finds another category title
$(this).nextUntil(".productlist .category").each(function() {
var li = $('a', this);
$("&lt;option /&gt;", {
"value" : li.attr("href"),
"text" : '- '+li.text()
}).appendTo(".productlist select");
});
});</pre>
<p>Done. For real-life example, you can view it on <a href="http://www.bluelounge.com/products/studiodesk" target="_blank">Bluelounge product page</a>.</p>
<p>The post <a href="https://sunarlim.com/2013/02/responsive-multi-level-menu-to-dropdown/">Responsive Multi-level Menu to Dropdown</a> appeared first on <a href="https://sunarlim.com">Michael Sunarlim</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sunarlim.com/2013/02/responsive-multi-level-menu-to-dropdown/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">728</post-id>	</item>
		<item>
		<title>Creating &#8220;Sticky&#8221; Vertical Menu with jQuery Waypoints</title>
		<link>https://sunarlim.com/2013/02/creating-sticky-vertical-menu-with-jquery-waypoints/</link>
					<comments>https://sunarlim.com/2013/02/creating-sticky-vertical-menu-with-jquery-waypoints/#respond</comments>
		
		<dc:creator><![CDATA[Michael]]></dc:creator>
		<pubDate>Mon, 18 Feb 2013 03:32:31 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[bluelounge]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[UI]]></category>
		<guid isPermaLink="false">https://sunarlim.com/?p=616</guid>

					<description><![CDATA[<p>Before last week, I had thought that making a sticky navigation would require a custom script and take a bit of time. By &#8220;sticky&#8221; it means an menu or element that is not always on top of the page but then sticks there after you scroll past a certain Y position. That was until I... <span class="more"><a class="more-link" href="https://sunarlim.com/2013/02/creating-sticky-vertical-menu-with-jquery-waypoints/">Continue reading <span class="meta-nav">&#8594;</span></a></span></p>
<p>The post <a href="https://sunarlim.com/2013/02/creating-sticky-vertical-menu-with-jquery-waypoints/">Creating &#8220;Sticky&#8221; Vertical Menu with jQuery Waypoints</a> appeared first on <a href="https://sunarlim.com">Michael Sunarlim</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Before last week, I had thought that making a sticky navigation would require a custom script and take a bit of time. By &#8220;sticky&#8221; it means an menu or element that is not always on top of the page but then sticks there after you scroll past a certain Y position. That was until I found <a href="http://imakewebthings.com/jquery-waypoints/" target="_blank">jQuery Waypoints</a> which makes it very easy to trigger the change in the element&#8217;s CSS position value and make it look as it stays on the top of the page.<br />
<span id="more-616"></span></p>
<p>Unfortunately it is not the end of the challenge. From jQuery Waypoint&#8217;s <a href="http://imakewebthings.com/jquery-waypoints/shortcuts/sticky-elements/" target="_blank">example</a> and other tutorials I found, they only show how to apply it when you have horizontal elements. In my case, I wanted to use it for Bluelounge&#8217;s products menu which has vertical orientation and quite long. The way sticky menu works is by changing the CSS position from relative to fixed and our menu&#8217;s height is 854px. This means if the viewport is less than that, the bottom area of the menu will not be viewable at all.</p>
<div id="attachment_617" style="width: 610px" class="wp-caption aligncenter"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-617" class="size-full wp-image-617" alt="View from smaller screen" src="https://i0.wp.com/sunarlim.com/wp-content/uploads/2013/02/vertical_waypoints_01.jpg?resize=600%2C673&#038;ssl=1" width="600" height="673" srcset="https://i0.wp.com/sunarlim.com/wp-content/uploads/2013/02/vertical_waypoints_01.jpg?w=600&amp;ssl=1 600w, https://i0.wp.com/sunarlim.com/wp-content/uploads/2013/02/vertical_waypoints_01.jpg?resize=267%2C300&amp;ssl=1 267w, https://i0.wp.com/sunarlim.com/wp-content/uploads/2013/02/vertical_waypoints_01.jpg?resize=150%2C168&amp;ssl=1 150w, https://i0.wp.com/sunarlim.com/wp-content/uploads/2013/02/vertical_waypoints_01.jpg?resize=200%2C224&amp;ssl=1 200w, https://i0.wp.com/sunarlim.com/wp-content/uploads/2013/02/vertical_waypoints_01.jpg?resize=400%2C448&amp;ssl=1 400w" sizes="(max-width: 600px) 100vw, 600px" data-recalc-dims="1" /><p id="caption-attachment-617" class="wp-caption-text">View from smaller screen</p></div>
<p>The idea was to keep the &#8220;default behavior&#8221; when scrolling past the assigned waypoint but then change the CSS position value when it is near the end of the page, before the footer. With this approach, visitors can scroll through the bottom of the page and see the rest of the menu. Note that our product pages are mostly not too long, so this solution could still be considered. If you have very long pages, then I would not recommend it because your users will have to scroll a lot before they can see the rest of the menu.</p>
<div id="attachment_620" style="width: 610px" class="wp-caption aligncenter"><img decoding="async" aria-describedby="caption-attachment-620" class="size-full wp-image-620" alt="When reaching the bottom of the page." src="https://i0.wp.com/sunarlim.com/wp-content/uploads/2013/02/vertical_waypoints_02.jpg?resize=600%2C420&#038;ssl=1" width="600" height="420" srcset="https://i0.wp.com/sunarlim.com/wp-content/uploads/2013/02/vertical_waypoints_02.jpg?w=600&amp;ssl=1 600w, https://i0.wp.com/sunarlim.com/wp-content/uploads/2013/02/vertical_waypoints_02.jpg?resize=300%2C210&amp;ssl=1 300w, https://i0.wp.com/sunarlim.com/wp-content/uploads/2013/02/vertical_waypoints_02.jpg?resize=150%2C105&amp;ssl=1 150w, https://i0.wp.com/sunarlim.com/wp-content/uploads/2013/02/vertical_waypoints_02.jpg?resize=200%2C140&amp;ssl=1 200w, https://i0.wp.com/sunarlim.com/wp-content/uploads/2013/02/vertical_waypoints_02.jpg?resize=400%2C280&amp;ssl=1 400w" sizes="(max-width: 600px) 100vw, 600px" data-recalc-dims="1" /><p id="caption-attachment-620" class="wp-caption-text">When reaching the bottom of the page.</p></div>
<p>So, how to achieve this? We need to create two waypoints: one at the start of the content (after header) and one at the end of the content (before footer).</p>
<h3>The Codes</h3>
<p>Here is the simplified version of page HTML structure:</p>
<p>[syntax_prettify linenums=&#8221;linenums&#8221;]<br />
&lt;div class=&quot;wrapper&quot; id=&quot;products&quot;&gt;<br />
  &lt;div class=&quot;container_16&quot;&gt;<br />
    &lt;div class=&quot;header&quot;&gt;<br />
      &lt;!&#8211; Header Content &#8211;&gt;<br />
    &lt;/div&gt;<br />
    &lt;div class=&quot;pagecontent sidebar&quot;&gt;<br />
      &lt;div class=&quot;grid productlist&quot;&gt; &lt;!&#8211; wrapper for menu &#8211;&gt;<br />
        &lt;!&#8211; start: Product Menu &#8211;&gt;<br />
        &lt;ul id=&quot;list-products&quot;&gt;<br />
          &lt;li class=&quot;category&quot;&gt;&lt;h3&gt;Cable Management&lt;/h3&gt;&lt;/li&gt;<br />
          &lt;li class=&quot;cable-management&quot;&gt;&lt;a href=&quot;/products/sumo/&quot; title=&quot;Sumo: A Heavyweight for small cables&quot;&gt;&lt;span&gt;Sumo&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;<br />
          &lt;li class=&quot;cable-management&quot;&gt;&lt;a href=&quot;/products/cableboxmini/&quot; title=&quot;CableBox Mini: Liven up your space&quot;&gt;&lt;span&gt;CableBox Mini&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;<br />
          &lt;li class=&quot;cable-management&quot;&gt;&lt;a href=&quot;/products/cableclip/&quot; title=&quot;CableClip: Sleek, minimalist design solution for managing cables of all sizes&quot;&gt;&lt;span&gt;CableClip&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;<br />
          &lt;li class=&quot;category&quot;&gt;&lt;h3&gt;Desks&lt;/h3&gt;&lt;/li&gt;<br />
          &lt;li class=&quot;desks&quot;&gt;&lt;a href=&quot;/products/studiodesk/&quot; title=&quot;StudioDesk: A traditional workspace with a modern twist&quot;&gt;&lt;span&gt;StudioDesk&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;<br />
        &lt;/ul&gt;<br />
        &lt;!&#8211; end: Product Menu &#8211;&gt;<br />
        &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;<br />
      &lt;/div&gt;<br />
      &lt;div class=&quot;grid details&quot;&gt;<br />
        &lt;!&#8211; Page Content &#8211;&gt;<br />
      &lt;/div&gt;<br />
      &lt;div class=&quot;clearfix&quot;&gt;&lt;/div&gt;<br />
    &lt;/div&gt;<br />
  &lt;/div&gt;<br />
&lt;/div&gt;</p>
<p>&lt;div class=&quot;footer&quot;&gt;<br />
  &lt;!&#8211; Footer Content &#8211;&gt;<br />
&lt;/div&gt;<br />
[/syntax_prettify]</p>
<p>And here is the JS code:</p>
<p>[syntax_prettify linenums=&#8221;linenums&#8221;]<br />
$(&#8216;.productlist&#8217;).waypoint({<br />
  handler: function(direction) {<br />
    $(&#8216;#list-products&#8217;).toggleClass(&#8216;sticky-top&#8217;); //change position to fixed by adding &#8216;sticky-top&#8217; class<br />
  }<br />
});<br />
$(&#8216;.footer&#8217;).waypoint({<br />
  offset: $(&#8216;#list-products&#8217;).height()+20, //calculate menu&#8217;s height and margin before footer<br />
  handler: function(direction) {<br />
    $(&#8216;#list-products&#8217;).toggleClass(&#8216;sticky-top&#8217;); //remove &#8216;sticky-top&#8217; class<br />
    $(&#8216;.productlist&#8217;).toggleClass(&#8216;sticky-bottom&#8217;); //change position to absolute for the wrapper<br />
  }<br />
});<br />
[/syntax_prettify]</p>
<p>Finally the simplified CSS code:</p>
<p>[syntax_prettify linenums=&#8221;linenums&#8221;]<br />
.sticky-top {<br />
  position: fixed;<br />
  top: 0;<br />
}</p>
<p>.sticky-bottom {<br />
  position: absolute;<br />
  bottom: 0;<br />
}<br />
[/syntax_prettify]</p>
<h3>The Logics</h3>
<p>As I have mentioned, Waypoints is really making things easy by allowing you to set your &#8216;anchors&#8217; within the page. So in line 1 of the JS, when the scroll hits <em>&lt;div class=&quot;productlist&quot;&gt;</em> it will toggle a new class <em>sticky-top</em> for the menu which changes the CSS position to <em>fixed</em> and make it stick to the top of the page.</p>
<p>The harder part is to tell the script that after reaching another waypoint, it has to remove the <em>sticky-top</em> class from the menu and make the menu&#8217;s wrapper stick to the end of the page&#8217;s content. To do this, we first need to calculate the position of the other waypoint. For this, we have to make use the <em>offset</em> option.</p>
<p>From Waypoints documentation:<br />
<strong>Offset</strong><br />
This option determines how far the top of the element must be from the top of the viewport to trigger the callback function.</p>
<p>Since the <em>&lt;div class=&quot;footer&quot;&gt;</em> is the element that we want to set as the new waypoint, we have to add the offset with the height of the menu by using jQuery&#8217;s height() function. I also added an extra 20px because there is 20px bottom margin from the page content to the footer.</p>
<h3>Real-life usage</h3>
<p>You can see the result on <a href="http://www.bluelounge.com/products/milo/" target="_blank" style="text-decoration: line-through;">Bluelounge product page</a>. Inside the product page, there are also other scripts running like the tabs and masonry so I have to add additional steps to make all of them work nicely together. But I am not going to the details and will save it for another time.</p>
<p>The technique is not perfect yet, you can probably still notice the page jumps a little. Not to mention a certain minimum height of the viewport is still required, which is half of the menu, so on very small desktop screens this will not work optimally. For now, I am quite happy with this and welcoming any suggestion to improve it further.</p>
<p><strong>Note:</strong> New <a href="http://www.bluelounge.com/" target="_blank">Bluelounge website</a> launched in the beginning of 2015, therefore the result link above is no longer working.</p>
<p>The post <a href="https://sunarlim.com/2013/02/creating-sticky-vertical-menu-with-jquery-waypoints/">Creating &#8220;Sticky&#8221; Vertical Menu with jQuery Waypoints</a> appeared first on <a href="https://sunarlim.com">Michael Sunarlim</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sunarlim.com/2013/02/creating-sticky-vertical-menu-with-jquery-waypoints/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">616</post-id>	</item>
	</channel>
</rss>
