<?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>jquery Archives - Michael Sunarlim</title>
	<atom:link href="https://sunarlim.com/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>https://sunarlim.com/tag/jquery/</link>
	<description>Random blurbs about web development, e-commerce and technology</description>
	<lastBuildDate>Sun, 24 Jan 2016 05:31:21 +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>jquery Archives - Michael Sunarlim</title>
	<link>https://sunarlim.com/tag/jquery/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">30613895</site>	<item>
		<title>Make Vimeo Lightbox Auto-Closes on Finish Using FancyBox</title>
		<link>https://sunarlim.com/2014/04/make-vimeo-lightbox-auto-closes-finish-using-fancybox/</link>
					<comments>https://sunarlim.com/2014/04/make-vimeo-lightbox-auto-closes-finish-using-fancybox/#comments</comments>
		
		<dc:creator><![CDATA[Michael]]></dc:creator>
		<pubDate>Sun, 13 Apr 2014 11:49:15 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[fancybox]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[vimeo]]></category>
		<guid isPermaLink="false">https://sunarlim.com/?p=980</guid>

					<description><![CDATA[<p>FancyBox has been my number one preference when I need to implement a jQuery-based lightbox on any web page I am working on. It is the most customizable and extensible jQuery plugin for this function. Since version 2.0, it also introduced a concept of &#8216;helpers&#8217; to reduce the size of the main JS file and... <span class="more"><a class="more-link" href="https://sunarlim.com/2014/04/make-vimeo-lightbox-auto-closes-finish-using-fancybox/">Continue reading <span class="meta-nav">&#8594;</span></a></span></p>
<p>The post <a href="https://sunarlim.com/2014/04/make-vimeo-lightbox-auto-closes-finish-using-fancybox/">Make Vimeo Lightbox Auto-Closes on Finish Using FancyBox</a> appeared first on <a href="https://sunarlim.com">Michael Sunarlim</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>FancyBox has been my number one preference when I need to implement a jQuery-based lightbox on any web page I am working on. It is the most customizable and extensible jQuery plugin for this function.</p>
<p>Since version 2.0, it also introduced a concept of &#8216;helpers&#8217; to reduce the size of the main JS file and also to allow developers to play more with its functionality with less risk of breaking the core functions when they are updated. Below I am going to show a little trick to modify FancyBox&#8217;s media helper to allow Vimeo link to auto-close when the video finishes.</p>
<p><span id="more-980"></span></p>
<h3>Vimeo API</h3>
<p>The first step to achieve this is by understanding <a title="Vimeo Player JavaScript API" href="http://developer.vimeo.com/player/js-api" target="_blank">Vimeo Player JavaScript API</a> and how to enable API calling for the videos. To save your time, there are two items you need to note:</p>
<ol>
<li>You need to turn on the API using <code>api=1</code> code and define the player ID ie. <code>player_id=vimeoplayer</code></li>
<li>Use Froogaloop, a JS mini-library written by Vimeo to communicate with their API. It can be downloaded <a title="Froogaloop on GitHub" href="https://github.com/vimeo/player-api/tree/master/javascript" target="_blank">here</a>.</li>
</ol>
<h3>Modifying Fancybox media helper file</h3>
<p>By default, the media helper file from FancyBox does not define the API and player ID. So we need to make minor change with the <code>helpers/jquery.fancybox-media.js</code>:</p>
<pre class="nums:false nums-toggle:false lang:js decode:true">vimeo : {
    matcher : /(?:vimeo(?:pro)?.com)\/(?:[^\d]+)?(\d+)(?:.*)/,
    params  : {
        autoplay      : 1,
        hd            : 1,
        show_title    : 1,
        show_byline   : 1,
        show_portrait : 0,
        fullscreen    : 1,
        api           : 1, // enable Vimeo Player API
        player_id     : 'fancybox-vimeo' // define Player ID
    },
    type : 'iframe',
    url  : '//player.vimeo.com/video/$1'
},</pre>
<p>&nbsp;</p>
<p>That&#8217;s it. You may want to save the helper file to another name, like <code>jquery.fancybox-media.custom.js</code></p>
<h3>Putting them together</h3>
<p>First call FancyBox scripts like you usually do, including the customized media helper file and Froogaloop.</p>
<pre class="nums:false nums-toggle:false lang:default decode:true">&lt;link rel="stylesheet" href="/path/to/js/lib/fancybox.v2/jquery.fancybox.css" type="text/css" media="screen" /&gt;
&lt;link rel="stylesheet" href="/path/to/js/lib/fancybox.v2/helpers/jquery.fancybox-buttons.css" type="text/css" media="screen" /&gt;
&lt;script type="text/javascript" src="/path/to/js/lib/jquery.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/js/lib/fancybox.v2/jquery.fancybox.pack.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/js/lib/fancybox.v2/helpers/jquery.fancybox-media.custom.js?v=1.0.6"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/js/lib/jquery.easing.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/js/lib/froogaloop.min.js"&gt;&lt;/script&gt;</pre>
<p>Next, let&#8217;s try to call FancyBox that auto-closes when the video has finished playing:</p>
<pre class="nums:false nums-toggle:false lang:xhtml decode:true  ">&lt;script type="text/javascript"&gt;
$(document).ready(function() {
    $("a#pt6vid").fancybox({
        tpl : {
            iframe   : '&lt;iframe id="fancybox-vimeo" name="fancybox-vimeo" class="fancybox-iframe" frameborder="0" vspace="0" hspace="0"&gt;&lt;/iframe&gt;'
        },
        helpers : {
            media : {} // call media helper
        },
        // below is where we call Vimeo Player API
        afterLoad: function(current, previous) {
            var iframe = $('#fancybox-vimeo')[0],
                    player = $f(iframe);
            // When the player is ready, add listeners for pause, finish, and playProgress
            player.addEvent('ready', function() {
                player.addEvent('finish', function(id) {
                    $.fancybox.close();
                });
            });
        }
    });
});
&lt;/script&gt;</pre>
<p>Done.</p>
<p>The post <a href="https://sunarlim.com/2014/04/make-vimeo-lightbox-auto-closes-finish-using-fancybox/">Make Vimeo Lightbox Auto-Closes on Finish Using FancyBox</a> appeared first on <a href="https://sunarlim.com">Michael Sunarlim</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sunarlim.com/2014/04/make-vimeo-lightbox-auto-closes-finish-using-fancybox/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">980</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>
		<item>
		<title>CrossSlide</title>
		<link>https://sunarlim.com/2008/09/crossslide/</link>
					<comments>https://sunarlim.com/2008/09/crossslide/#respond</comments>
		
		<dc:creator><![CDATA[Michael]]></dc:creator>
		<pubDate>Sun, 28 Sep 2008 16:42:08 +0000</pubDate>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<guid isPermaLink="false">http://wp.sunarlim.com.com/?p=172</guid>

					<description><![CDATA[<p>I really love Slideshow 2! JavaScript class for creating slideshows. It is super easy to use and customize. The only thing I wish it was based on jQuery instead of MooTools. Well, I just found CrossSlide. I have not actually tested yet, but from the demo it has the basic functions of Slideshow 2! except... <span class="more"><a class="more-link" href="https://sunarlim.com/2008/09/crossslide/">Continue reading <span class="meta-nav">&#8594;</span></a></span></p>
<p>The post <a href="https://sunarlim.com/2008/09/crossslide/">CrossSlide</a> appeared first on <a href="https://sunarlim.com">Michael Sunarlim</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I really love <a href="http://www.electricprism.com/aeron/slideshow/" target="_blank">Slideshow 2!</a> JavaScript class for creating slideshows. It is super easy to use and customize. The only thing I wish it was based on jQuery instead of MooTools.</p>
<p>Well, I just found <a href="http://www.gruppo4.com/~tobia/cross-slide.shtml" target="_blank">CrossSlide</a>. I have not actually tested yet, but from the demo it has the basic functions of Slideshow 2! except the navigation bar. The better thing of course because it is based on jQuery, so I am happy to have this option. I am sure over time more feature will be added.</p>
<p>My full support for Tobia Conforto, the creator for this cool jQuery plugin.</p>
<p>The post <a href="https://sunarlim.com/2008/09/crossslide/">CrossSlide</a> appeared first on <a href="https://sunarlim.com">Michael Sunarlim</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sunarlim.com/2008/09/crossslide/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">172</post-id>	</item>
	</channel>
</rss>
