<?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/"
	>

<channel>
	<title>Webmaster-Source &#187; javascript</title>
	<atom:link href="https://www.webmaster-source.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.webmaster-source.com</link>
	<description>Useful Resources For Webmasters</description>
	<lastBuildDate>Thu, 24 Aug 2017 02:01:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>Node.js the Right Way</title>
		<link>https://www.webmaster-source.com/2014/01/08/node-js-the-right-way/</link>
		<comments>https://www.webmaster-source.com/2014/01/08/node-js-the-right-way/#comments</comments>
		<pubDate>Wed, 08 Jan 2014 11:29:12 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Node.js]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=5271</guid>
		<description><![CDATA[Looking to quickly get started with Node.js without learning bad habits? Node.js the Right Way is a short and concise—100 pages—book that you can easily read in an afternoon (maybe two if you&#8217;re following along with the examples), promising a focused, tutorial-based experience. The book makes the assumption that you&#8217;re already somewhat familiar with programming [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img style=' float: right; padding: 4px; margin: 0 0 2px 7px;'  class="alignright size-full wp-image-5272" alt="Node.js The Right Way" src="//www.webmaster-source.com/wp-content/uploads/2014/01/nodejs-right-way.png" width="160" height="197" />Looking to quickly get started with Node.js without learning bad habits? <em>Node.js the Right Way</em> is a short and concise—100 pages—book that you can easily read in an afternoon (maybe two if you&#8217;re following along with the examples), promising a focused, tutorial-based experience.</p>
<p>The book makes the assumption that you&#8217;re already somewhat familiar with programming and the JavaScript language in particular. Instead of wasting time with absolute basics, it dives right in to Node. The first two chapters explain what exactly Node is, and how the the event loop works. It covers the differences between synchronous and asynchronous tasks, illustrating the reason you want to avoid blocking I/O. The next two chapters deal with sockets, serializing data and message queues. Other sections deal with databases (using CouchDB as an example), unit tests, building and consuming RESTful APIs and single-page web apps.</p>
<p>If you work your way through the examples in the book, you&#8217;ll end up building a reasonably complex web app and batch-importing a bunch of data from Project Gutenberg.</p>
<p><em>Node.js the Right Way</em> is the best introduction to Node that I&#8217;ve seen so far. It&#8217;s concise enough it won&#8217;t take up a lot of your time, covers things more thorougly than a 500-word blog post or hour-long screencast, and there&#8217;s no magic &#8220;just copy and paste this, I&#8217;m not going to bother explaining it.&#8221; You should come out of it knowing where to go to keep learning. It&#8217;s easy enough to think &#8220;I used <a href="expressjs.com">Express</a> for this, and <a href="http://gruntjs.com/">Grunt</a> for that. Maybe I should search for more information about those tools.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2014/01/08/node-js-the-right-way/feed/</wfw:commentRss>
		<slash:comments>158</slash:comments>
		</item>
		<item>
		<title>List.js: Table and List Sorting in 5kb of JavaScript</title>
		<link>https://www.webmaster-source.com/2013/12/11/list-js-table-and-list-sorting-in-5kb-of-javascript/</link>
		<comments>https://www.webmaster-source.com/2013/12/11/list-js-table-and-list-sorting-in-5kb-of-javascript/#comments</comments>
		<pubDate>Wed, 11 Dec 2013 13:52:43 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Software & Scripts]]></category>
		<category><![CDATA[(x)html]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=5252</guid>
		<description><![CDATA[List.js is a tiny (five kilobytes!) library that can add dynamic sorting, searching and pagination to HTML lists and tables. It requires no dependencies, and claims to be able to handle lists with &#8220;thousands of items.&#8221; It also includes a templating system that makes it possible to allow the addition and editing of items, a [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="http://listjs.com/">List.js</a> is a tiny (five kilobytes!) library that can add dynamic sorting, searching and pagination to HTML lists and tables. It requires no dependencies, and claims to be able to handle lists with &#8220;thousands of items.&#8221;</p>
<p>It also includes a templating system that makes it possible to allow the addition and editing of items, a pagination plugin, and a plugin that adds <a href="http://listjs.com/examples/fuzzy-search">fuzzy search</a>. (Also, they get bonus points for using characters from <a href="http://en.wikipedia.org/wiki/The_Secret_of_Monkey_Island"><em>The Secret of Monkey Island</em></a> as an example.)</p>
<p>The script looks very promising, though there is one caveat about the file size claim: the minified version is 5kb when served with gzip compression. If, for whatever reason, your server is not configured to do so, then it&#8217;s more to the order of 15kb. Still small, but not quite as amazingly so.</p>
<p><a href="http://listjs.com">List.js</a> [listjs.com]</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2013/12/11/list-js-table-and-list-sorting-in-5kb-of-javascript/feed/</wfw:commentRss>
		<slash:comments>52</slash:comments>
		</item>
		<item>
		<title>Custom JavaScript Twitter Widgets in an API 1.1 World</title>
		<link>https://www.webmaster-source.com/2013/07/03/custom-javascript-twitter-widgets-in-an-api-1-1-world/</link>
		<comments>https://www.webmaster-source.com/2013/07/03/custom-javascript-twitter-widgets-in-an-api-1-1-world/#comments</comments>
		<pubDate>Wed, 03 Jul 2013 11:46:27 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=5131</guid>
		<description><![CDATA[Continuing their gradual shutdown of old APIs (following the launch of version 1.1 of their API), Twitter recently pulled the plug on their old-style widgets and the unauthenticated search API. This means if you had a fancy custom-designed JavaScript widget to show off your latest tweets, it&#8217;s not going to work anymore. The only officially [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="http://matt.harzewski.com/"><img style=' float: right; padding: 4px; margin: 0 0 2px 7px;'  class="alignright size-full wp-image-5132" alt="My Twitter Widget" src="//www.webmaster-source.com/wp-content/uploads/2013/06/mvhtwitterwidget.png" width="200" height="382" /></a>Continuing their gradual shutdown of old APIs (following the launch of version 1.1 of their API), Twitter recently pulled the plug on their old-style widgets and the unauthenticated search API. This means if you had a fancy custom-designed JavaScript widget to show off your latest tweets, it&#8217;s not going to work anymore. The only officially supported options are the <a href="https://twitter.com/settings/widgets">new widgets</a> or a server-side solution with OAuth authentication.</p>
<p>What can you do if you don&#8217;t like either option?</p>
<p><a href="http://jasonmayes.com/projects/twitterApi/">Jason Mayes</a> hacked together <a href="http://codepen.io/jasonmayes/pen/Ioype">a clever bit of JavaScript</a> that loads up one of the new Twitter widgets, scrapes the content out, and reformats it into nicer unstyled HTML. Then you can style it however you want in your stylesheet.</p>
<p>I&#8217;m using this right now on <a href="http://matt.harzewski.com/">my personal blog</a>, since Twitter&#8217;s new widgets don&#8217;t look very good when they&#8217;re crammed into a narrow sidebar.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2013/07/03/custom-javascript-twitter-widgets-in-an-api-1-1-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the WordPress 3.5 Media Uploader in Your Plugin or Theme</title>
		<link>https://www.webmaster-source.com/2013/02/06/using-the-wordpress-3-5-media-uploader-in-your-plugin-or-theme/</link>
		<comments>https://www.webmaster-source.com/2013/02/06/using-the-wordpress-3-5-media-uploader-in-your-plugin-or-theme/#comments</comments>
		<pubDate>Wed, 06 Feb 2013 11:21:50 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Themes]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=5001</guid>
		<description><![CDATA[Back in 2010, I wrote a post on Using the WordPress Uploader in Your Plugin or Theme that went on to be one of my most popular tutorials of all time. Then the WordPress team went and added a much cooler media uploader in version 3.5 and make that post outdated. Since most of you [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Back in 2010, I wrote a post on <a href="http://www.webmaster-source.com/2010/01/08/using-the-wordpress-uploader-in-your-plugin-or-theme/">Using the WordPress Uploader in Your Plugin or Theme</a> that went on to be one of my most popular tutorials of all time. Then the WordPress team went and added a much cooler media uploader in version 3.5 and make that post outdated. Since most of you probably want to add the <em>new</em> uploader in a theme or plugin you&#8217;re working on right now, I figured it was time for an updated post.</p>
<p style="text-align: center"><img style=' display: block; margin-right: auto; margin-left: auto;'  class="aligncenter size-full wp-image-5002 imgborder" alt="WordPress 3.5 Media Uploader" src="//www.webmaster-source.com/wp-content/uploads/2013/02/wp35mediauploader.png" width="600" height="286" /></p>
<p>The process required to add the new uploader is a bit different, but not too much more difficult. I was able to adapt the old tutorial a little, so it shouldn&#8217;t be too hard to replace some code in an existing project and get the new uploader instead of the old.<span id="more-5001"></span></p>
<p>For the sake of simplicity, let&#8217;s start with the same HTML snippet as in the old tutorial. This goes along with the rest of the HTML for your admin page, or wherever in the admin you&#8217;re trying to add an upload field.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;label for=&quot;upload_image&quot;&gt;
	&lt;input id=&quot;upload_image&quot; type=&quot;text&quot; size=&quot;36&quot; name=&quot;ad_image&quot; value=&quot;http://&quot; /&gt; 
	&lt;input id=&quot;upload_image_button&quot; class=&quot;button&quot; type=&quot;button&quot; value=&quot;Upload Image&quot; /&gt;
	&lt;br /&gt;Enter a URL or upload an image
&lt;/label&gt;
</pre>
<p>Now we need to load up the necessary JavaScript files.</p>
<pre class="brush: php; title: ; notranslate">
add_action('admin_enqueue_scripts', 'my_admin_scripts');

function my_admin_scripts() {
	if (isset($_GET['page']) &amp;&amp; $_GET['page'] == 'my_plugin_page') {
		wp_enqueue_media();
		wp_register_script('my-admin-js', WP_PLUGIN_URL.'/my-plugin/my-admin.js', array('jquery'));
		wp_enqueue_script('my-admin-js');
	}
}
</pre>
<p>We bind the <code>my_admin_scripts()</code> function to the <code>admin_enqueue_scripts</code> hook, and enqueue both the media scripts and our own JavaScript file. Also, the scripts will only be loaded if the current page is equal to &#8220;my_plugin_page,&#8221; which you would of course replace with the slug your <a href="http://codex.wordpress.org/Administration_Menus">admin menu</a> has.</p>
<p>Now for the complicated part: the script that hooks into the uploader. Continuing with the above example, it would be named <code>my-admin.js</code>.</p>
<pre class="brush: jscript; title: ; notranslate">
jQuery(document).ready(function($){


	var custom_uploader;


	$('#upload_image_button').click(function(e) {

		e.preventDefault();

		//If the uploader object has already been created, reopen the dialog
		if (custom_uploader) {
			custom_uploader.open();
			return;
		}

		//Extend the wp.media object
		custom_uploader = wp.media.frames.file_frame = wp.media({
			title: 'Choose Image',
			button: {
				text: 'Choose Image'
			},
			multiple: false
		});

		//When a file is selected, grab the URL and set it as the text field's value
		custom_uploader.on('select', function() {
			attachment = custom_uploader.state().get('selection').first().toJSON();
			$('#upload_image').val(attachment.url);
		});

		//Open the uploader dialog
		custom_uploader.open();

	});


});
</pre>
<p>When the button is clicked, it creates a new instance of the <code>wp.media</code> object and configures it to only accept a single file, since the text field can only hold one file URL. Then it binds a function to the selection action, which gets the file attributes when an image is chosen and sets the <code>#upload_image</code> text field value to the file&#8217;s URL.</p>
<p>Providing everything went as expected, you should have a form field that will accept an arbitrary URL, or allow the user to upload one.</p>
<p><img style=' display: block; margin-right: auto; margin-left: auto;'  src="//www.webmaster-source.com/wp-content/uploads/2013/02/wp35mediauploader-field.png" alt="File Upload Field" width="352" height="44" class="aligncenter size-full wp-image-5005" /></p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2013/02/06/using-the-wordpress-3-5-media-uploader-in-your-plugin-or-theme/feed/</wfw:commentRss>
		<slash:comments>70</slash:comments>
		</item>
		<item>
		<title>Getting More From Twitter Bootstrap&#8217;s Typeahead Library</title>
		<link>https://www.webmaster-source.com/2012/11/07/getting-more-from-twitter-bootstraps-typeahead-library/</link>
		<comments>https://www.webmaster-source.com/2012/11/07/getting-more-from-twitter-bootstraps-typeahead-library/#comments</comments>
		<pubDate>Wed, 07 Nov 2012 10:26:08 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Twitter Bootstrap]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=4872</guid>
		<description><![CDATA[Twitter Bootstrap comes packaged with a simple auto-complete library that&#8217;s stylistically integrated into the CSS framework. It&#8217;s convenient, but not the most-documented part of Bootstrap. I was working on a hobby project recently, and I wanted to have an auto-completing search field, but it took a bit of work to extend the basic implementation. The [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img style=' float: right; padding: 4px; margin: 0 0 2px 7px;'  src="//www.webmaster-source.com/wp-content/uploads/2012/10/bootstrap-typeahead.png" alt="" title="Modified Typeahead in Twitter Bootstrap" width="263" height="115" class="alignright imgborder size-full wp-image-4873" />Twitter Bootstrap comes packaged with <a href="http://twitter.github.com/bootstrap/javascript.html#typeahead">a simple auto-complete library</a> that&#8217;s stylistically integrated into the CSS framework. It&#8217;s convenient, but not the most-documented part of Bootstrap. I was working on a hobby project recently, and I wanted to have an auto-completing search field, but it took a bit of work to extend the basic implementation.</p>
<p>The first, and probably most important, step was to implement an AJAX data source. The plugin supports this out of the box, but the documentation page doesn&#8217;t have an example. It&#8217;s easy enough. You pass a function that takes the query and hands it off to one of jQuery&#8217;s magic asynchronous request functions, like so:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() {
	$(&quot;#searchfield&quot;).typeahead({
		minLength: 3,
		source: function(query, process) {
			$.post('/search/typeahead', { q: query, limit: 8 }, function(data) {
			 	process(JSON.parse(data));
			});
		}
	});
});
</pre>
<p>Your request URL needs to respond with a JSON array of strings, which the typeahead library will process. The variables &#8220;q&#8221; and &#8220;limit&#8221; are sent along with the POST request in this example, and a PHP back-end returns the relevant data in response.<span id="more-4872"></span></p>
<pre class="brush: plain; title: ; notranslate">[&quot;Electric Light Orchestra&quot;, &quot;Elvis Costello&quot;, &quot;Eric Clapton&quot;]</pre>
<p>Once I had the asynchronous search working, I decided that it would be better if the user was taken to the search page as soon as they selected a suggested item, rather than having them click a search button. So I hooked in to the updater method, which runs whenever an item is selected.</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() {
	$(&quot;#searchfield&quot;).typeahead({
		minLength: 3,
		source: function(query, process) {
			$.post('/search/typeahead', { q: query, limit: 8 }, function(data) {
			 	process(JSON.parse(data));
			});
		},
		updater: function (item) {
			document.location = &quot;/search?q=&quot; + encodeURIComponent(item);
			return item;
		}
	});
});
</pre>
<p>It&#8217;s just a simple matter of intercepting the selected item and jumping to a new page, passing the search string in the query. As far as I can tell, <code>updater</code> is not documented at all on the Bootstrap site.</p>
<p>Now&#8230;what if a user doesn&#8217;t want to search for one of the suggestions? In its present form, the typeahead doesn&#8217;t give much choice. If it finds a suggestion, it&#8217;s automatically selected. While this is good for some situations, it might not make sense for some. My solution was to dynamically insert an additional item at the top of the suggestions list, matching the search query. The <code>sorter</code> function worked well for that, as it runs whenever the list is updated.</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() {
	$(&quot;#searchfield&quot;).typeahead({
		minLength: 3,
		source: function(query, process) {
			$.post('/search/typeahead', { q: query, limit: 8 }, function(data) {
			 	process(JSON.parse(data));
			});
		},
		updater: function (item) {
			document.location = &quot;/search?q=&quot; + encodeURIComponent(item);
			return item;
		},
		sorter: function (items) {
			items.unshift(this.query);
			return items;
		}
	});
});
</pre>
<p>You just slip the query into the items array with <code>unshift</code> and return the array with no further tampering.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2012/11/07/getting-more-from-twitter-bootstraps-typeahead-library/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Animating a CSS Sprite With JavaScript</title>
		<link>https://www.webmaster-source.com/2012/06/04/animating-a-css-sprite-with-javascript/</link>
		<comments>https://www.webmaster-source.com/2012/06/04/animating-a-css-sprite-with-javascript/#comments</comments>
		<pubDate>Mon, 04 Jun 2012 11:58:52 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[sprites]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=4700</guid>
		<description><![CDATA[Take a look at this demo, and guess how the animation is achieved. It&#8217;s not an animated GIF. It&#8217;s a PNG sprite that is brought to life with a little bit of JavaScript. The sprite image is a long strip containing each frame of the animation. The stylesheet sets it as the background of a [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Take a look at <a href="http://www.webmaster-source.com/static/demos/jsspriteanim/">this demo</a>, and guess how the animation is achieved. It&#8217;s not an animated GIF. It&#8217;s a PNG sprite that is brought to life with a little bit of JavaScript.</p>
<p>The sprite image is a long strip containing each frame of the animation. The stylesheet sets it as the background of a DIV, and the dimensions are set so you can only see one frame at a time. Then a script uses a timer loop to continuously shift down the line, resetting once it reaches the end. (A more complex version of this effect can be seen in this <a href="http://www.google.com/doodles/martha-grahams-117th-birthday">Google Doodle</a>.)</p>
<p><a href="http://www.webmaster-source.com/static/demos/jsspriteanim/"><img style=' display: block; margin-right: auto; margin-left: auto;'  class="aligncenter size-full wp-image-4701 imgborder" title="The Sprite" src="//www.webmaster-source.com/wp-content/uploads/2012/06/animsprite-puzzlesprite.png" alt="" width="600" height="63" /></a></p>
<p>It works just like the sprites traditionally used in video games. It&#8217;s more efficient to load one image from a slow data source, whether it&#8217;s a hard disk or an internet connection, and only show a piece of it at a time, than to load dozens of images and alternate between them. (It saves some overhead in other ways in a performance-minded environment like a game, as well.)<span id="more-4700"></span></p>
<h3>Why not just use an animated GIF?</h3>
<p>Aside from the simple fact that it&#8217;s more fun, the Graphics Interchange Format has some limitations that make it unsuitable for certain applications. It doesn&#8217;t work very well at all for photographic images, and it only has very basic transparency support. JPEG is far better for photographs, and PNG for images with flatter colors.</p>
<p>There <em>is</em> another image format that supports animation, the animated PNG format (APNG), but support for it is sorely lacking. Most popular image editors don&#8217;t support it natively, and only a couple of browsers can display them without third-party extensions. Firefox/Gecko and Opera are about the extent of browser support for APNG. Internet Explorer can&#8217;t display them at all, and Chrome requires a third-party extension.</p>
<p>By using a sprite, you have an image format that fits your needs, and still have animation. Oh, and you can start and stop the animation at will, through JavaScript.</p>
<h3>Implementation</h3>
<p>For starters, you need an element to hold the sprite. I ended up using a DIV with an ID of &#8220;sprite.&#8221;</p>
<pre class="brush: xml; title: ; notranslate">&lt;div id=&quot;sprite&quot;&gt;&lt;/div&gt;</pre>
<p>Then you need to style the element. (If it&#8217;s not already a block-level element like a DIV, you may need to add <code>display:block</code>.) It&#8217;s height should be the height of your sprite image, and the width should be the width of a single frame. My image is 200 pixels high, and a frame is 300 pixels wide.</p>
<pre class="brush: css; title: ; notranslate">
#sprite {
width: 300px;
height: 200px;
margin: 30px auto;
background-image: url(sprite.png);
}
</pre>
<p>The most important part, of course, is the script. I&#8217;m using some jQuery, simply because it&#8217;s a convenient way to handle my button events. You could easily adapt it to work without, though.</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function(){

var frameWidth = 300;
var frameHeight = 200;
var spriteWidth = 5400;
var spriteHeight = 200;
var spriteElement = document.getElementById(&quot;sprite&quot;);

var curPx = 0;
var ti;

function animateSprite() {

spriteElement.style.backgroundPosition = curPx + 'px 0px';
curPx = curPx + frameWidth;

if (curPx &gt;= spriteWidth) {
curPx = 0;
}

ti = setTimeout(animateSprite, 80);

}

animateSprite();

});
</pre>
<p>The block of variables at the top set the frame dimensions, the dimensions of the sprite image, and the element containing the sprite. Then a timer is set, firing once per 80 milliseconds, which runs the <code>animateSprite()</code> function. Every time the function runs, it sets the background offset to <code>curPx</code>, and adds the frame width to <code>curPx</code>, so the next frame will be displayed in the following iteration. If <code>curPx</code> reaches the last frame, it&#8217;s reset to zero, so the animation will wrap around.</p>
<p>As an added bonus, you can start and stop the animation at will through the script. I just added some click events to a couple of links for illustrative purposes.</p>
<pre class="brush: jscript; title: ; notranslate">
$(&quot;#stop&quot;).click(function() {
clearTimeout(ti);
});

$(&quot;#start&quot;).click(function() {
ti = setTimeout(animateSprite, 80);
});
</pre>
<p>You can see <a href="http://www.webmaster-source.com/static/demos/jsspriteanim/">the finished example in action here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2012/06/04/animating-a-css-sprite-with-javascript/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>BrowserQuest: A Massively Multiplayer Game in HTML5 and JavaScript</title>
		<link>https://www.webmaster-source.com/2012/03/29/browserquest-a-massively-multiplayer-game-in-html5-and-javascript/</link>
		<comments>https://www.webmaster-source.com/2012/03/29/browserquest-a-massively-multiplayer-game-in-html5-and-javascript/#comments</comments>
		<pubDate>Thu, 29 Mar 2012 11:56:49 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[MMORPGs]]></category>
		<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=4577</guid>
		<description><![CDATA[Imagine a massively multiplayer game using HTML5 features, such as Canvas and WebSocket, that works in any modern browser. Ridiculous, you say? Then you haven&#8217;t seen BrowserQuest yet. The clever demonstration, featured on the Mozilla Hacks blog, works on both desktops and mobile devices, in all it&#8217;s scrolling two-dimensional glory. It&#8217;s rendered on an HTML5 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Imagine a massively multiplayer game using HTML5 features, such as Canvas and WebSocket, that works in any modern browser. Ridiculous, you say? Then you haven&#8217;t seen <a href="http://browserquest.mozilla.org/">BrowserQuest</a> yet.</p>
<p style="text-align: center;"><a href="https://hacks.mozilla.org/2012/03/browserquest/"><img style=' display: block; margin-right: auto; margin-left: auto;'  class="aligncenter size-full wp-image-4578 imgborder" title="BrowserQuest" src="//www.webmaster-source.com/wp-content/uploads/2012/03/browserquest.jpg" alt="" width="600" height="307" /></a></p>
<p>The clever demonstration, <a href="https://hacks.mozilla.org/2012/03/browserquest/">featured on the Mozilla Hacks blog</a>, works on both desktops and mobile devices, in all it&#8217;s scrolling two-dimensional glory. It&#8217;s rendered on an HTML5 Canvas, uses WebSockets to stay in constant communication with the Node.js server, saves your progress with the local storage API, preloads the map in a different thread with Web Workers, plays sound with HTML5 Audio and even uses media queries to adapt to different devices. Oh, and the source code is all available on <a href="https://github.com/mozilla/BrowserQuest">GitHub</a>.</p>
<p>The game is largely exploring, hacking-and-slashing monsters along the way, while you collect achievements. It has chat, and you can find new items to replace your default gear, but no player-versus-player combat.</p>
<p>My laptop&#8217;s fans stayed far quieter than they would while playing a similar Flash game, which I would say says something about the level of optimization browsers have done when compared to OS X/Linux versions of Flash.</p>
<p>I think we&#8217;ll be seeing more games built this way in the near future, and 3D games once WebGL reaches the same level of maturity and browser support.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2012/03/29/browserquest-a-massively-multiplayer-game-in-html5-and-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thinking Async</title>
		<link>https://www.webmaster-source.com/2012/03/16/thinking-async/</link>
		<comments>https://www.webmaster-source.com/2012/03/16/thinking-async/#comments</comments>
		<pubDate>Fri, 16 Mar 2012 11:28:03 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[(x)html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=4554</guid>
		<description><![CDATA[I&#8217;ve written about loading JavaScript asynchronously in the past, as it&#8217;s a great way to decrease load times and prevent hang-ups when third-party scripts don&#8217;t load properly. But Chris Coyier has went and compiled the definitive guide. It covers the basic concepts and reasons for doing it, as well as different methods for implementing it; [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve written about <a href="http://www.webmaster-source.com/2010/06/07/loading-javascript-asynchronously/">loading JavaScript asynchronously</a> in the past, as it&#8217;s a great way to decrease load times and prevent hang-ups when third-party scripts don&#8217;t load properly. But Chris Coyier has went and compiled <a href="http://css-tricks.com/thinking-async/">the definitive guide</a>. It covers the basic concepts and reasons for doing it, as well as different methods for implementing it; the easy HTML5 way and using embedded scripts to inject a non-blocking call to an external script.</p>
<p>Its a nice long and informative article, and worth a look if you&#8217;re looking to do some performance optimization of web site. (Be sure to <a href="http://www.webmaster-source.com/2009/11/06/learning-css-sprites/">look into sprites</a> after you&#8217;ve switched to loading JavaScript asynchronously!)</p>
<p><a href="http://css-tricks.com/thinking-async/">Thinking Async</a> [CSS-Tricks]</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2012/03/16/thinking-async/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tinycon: Favicon Alert Bubbles</title>
		<link>https://www.webmaster-source.com/2012/02/27/tinycon-favicon-alert-bubbles/</link>
		<comments>https://www.webmaster-source.com/2012/02/27/tinycon-favicon-alert-bubbles/#comments</comments>
		<pubDate>Mon, 27 Feb 2012 11:08:39 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Software & Scripts]]></category>
		<category><![CDATA[favicon]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[notifications]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=4534</guid>
		<description><![CDATA[Tinycon is a neat script that manipulates the favicon of a page. Using a simple JavaScript call, you can add a little alert bubble over the icon, and change the number within. If the browser doesn&#8217;t support Canvas, it falls back to appending a number to the page title, like GMail does. Very cool. Now [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img style=' float: right; padding: 4px; margin: 0 0 2px 7px;'  class="alignright size-full wp-image-4535 imgborder" title="Tinycon" src="//www.webmaster-source.com/wp-content/uploads/2012/02/tinycon.png" alt="" width="245" height="66" /><a href="http://tommoor.github.com/tinycon/">Tinycon</a> is a neat script that manipulates the favicon of a page. Using a simple JavaScript call, you can add a little alert bubble over the icon, and change the number within. If the browser doesn&#8217;t support Canvas, it falls back to appending a number to the page title, like GMail does.</p>
<p>Very cool. Now I just need to think of something to use it for&#8230;</p>
<p><a href="http://tommoor.github.com/tinycon/">Tinycon &#8211; Favicon Alert Bubbles</a> [GitHub]</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2012/02/27/tinycon-favicon-alert-bubbles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSFiddle: A Playground for Web Developers</title>
		<link>https://www.webmaster-source.com/2012/01/05/jsfiddle-a-playground-for-web-developers/</link>
		<comments>https://www.webmaster-source.com/2012/01/05/jsfiddle-a-playground-for-web-developers/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 12:01:33 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[(x)html]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=4420</guid>
		<description><![CDATA[JSFiddle is a sort of interactive pastebin site that I&#8217;ve been finding useful lately. It features three panes for entering HTML, CSS and JavaScript, and a fourth where the resulting output is rendered. If you save the workspace, it generates a URL like http://jsfiddle.net/fLP64/ and will even save each revision as you update it. You [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="http://jsfiddle.net/">JSFiddle</a> is a sort of interactive <a href="http://en.wikipedia.org/wiki/Pastebin">pastebin</a> site that I&#8217;ve been finding useful lately. It features three panes for entering HTML, CSS and JavaScript, and a fourth where the resulting output is rendered. If you save the workspace, it generates a URL like <code>http://jsfiddle.net/fLP64/</code> and will even save each revision as you update it. You can share the URL to show off the result, and the other user can play with the code as well.</p>
<p>This is great for two scenarios. You can use it to experiment with a bit of CSS or JavaScript for brainstorming purposes, or you can use it if you need to ask someone for help. (It&#8217;s a lot easier to figure out what&#8217;s going wrong with someone&#8217;s code or markup if you can jump right in and start messing with the code.) Chris Coyier (of <a href="http://css-tricks.com/">CSS-Tricks</a>) uses it all the time to show off CSS experiments that will likely be used in future posts of his.</p>
<p style="text-align: center;"><a href="http://jsfiddle.net/fLP64/"><img style=' display: block; margin-right: auto; margin-left: auto;'  class="aligncenter size-full wp-image-4421 imgborder" title="JSFiddle" src="//www.webmaster-source.com/wp-content/uploads/jsfiddle.png" alt="" width="600" height="288" /></a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2012/01/05/jsfiddle-a-playground-for-web-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/


Served from: www.webmaster-source.com @ 2026-04-05 16:15:46 by W3 Total Cache
-->