Oct 29 2009

JQuery Part 2 – Basic Animation

Welcome to JQuery part 2, using basic animation techniques. You should already have a basic understanding of JQuery and it’s elements to complete this tutorial. If you don’t, please refer to my JQuery Introduction post found here. Now to get started…

Let’s start by creating a basic HTML page and call it index.html in the root of our web servers directory and add a basic page structure to that file. Let’s also make sure that we have the JQuery libraries imported and ready to use.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>JQuery Animations</title>
 
		<script type="text/javascript" src="lib/jquery.js" />	
 
	</head>
	<body>
	</body>
</html>

Now, in order to complete animation we will need to display an element to animate. The easiest way to do this is to use some basic CSS. So for the purpose of this tutorial let’s create a style.css file and put it in the root of our directory. Let’s then link it to our index.html file so that we can use it.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>JQuery Animations</title>
 
		<script type="text/javascript" src="lib/jquery.js" />
 
		<link rel="stylesheet" href="style.css" type="text/css" />
 
	</head>
	<body>
	</body>
</html>

Now that we have our CSS file linked to our HTML we’re going to need to add an element to animate. For this demonstration we’re just going to use a red box that’s 100px by 100px inside a div. Let’s add that to our CSS file.

#redBox
{
	width:100px;
	height:100px;
	background-color: red;
}

Now we’ll add the appropriate div tags to our HTML file so that our red box shows up. We’re also going to add an anchor tag directly below our red box to toggle the box between showing and disappearing.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>JQuery Animations</title>
 
	<script type="text/javascript" src="lib/jquery.js" />
 
	<link rel="stylesheet" href="style.css" type="text/css" />
 
</head>
	<body>
		<div id="redBox"></div>
		<a href="#">Show/Hide</a>
	</body>
</html>

Now we’re all ready to start coding our JQuery. If you run the HTML file right now you should see a red box sitting at the top left hand corner of the page. Right now the red box shouldn’t do anything as we haven’t coded the JQuery. So let’s start out by using the document ready function. and adding a function to all of our anchor tags.

<script>
	$(document).ready(function(){
		$('a').click(function({
 
		));
	});
</script>

Now we’re ready to be using some of the animation methods found in the JQuery library. First, since the box is by default showing up in the browser we’re going to make it hide by using the .hide() function. The .hide() function can be used without any parameters being passed or you can pass a speed and an optional callback(). The callback is a function to be executed when the animation has been completed. For the sake of this tutorial we’re only going to cover the speed parameter.

<script>
	$(document).ready(function(){
		$('a').click(function({
			$('#redBox').hide('slow');
		));
	});
</script>

Now, if you include the script section in the header of your index.html document and run it, when you click the anchor tag you should see the red box that we created disappear. However now the red box is gone and we can’t get it back. We’re going to need to change this so that we can get it back by clicking on the anchor tag again. In order to get this we’re going to need to add another function and pass it as a parameter to our .click() function for our anchor tags.

<script>
	$(document).ready(function(){
		$('a').click(function({
			$('#redBox').hide('slow');
		},function(){
			$('#redBox').show('slow');
		});
	});
	</script>

Since we’re adding the new function as another parameter to the click function, we need to terminate the current function before starting the new one. This is why we need to close the curly braces from the previous function before we start another. If we didn’t close the curly braces and just put it inside the first function then every time we clicked on the anchor tag, it would disappear and then show again without pressing the anchor tag. Now when we put that all together and run it, whenever we click the anchor tag the box should disappear and then re-appear when we click it again. Here is the complete code.

<html>
<head>
	<title>JQuery Animations</title>
 
	<script type="text/javascript" src="lib/jquery.js" />
 
	<link rel="stylesheet" href="style.css" type="text/css" />
 
	<script>
	$(document).ready(function(){
		$('a').click(function({
			$('#redBox').hide('slow');
		},function(){
			$('#redBox').show('slow');
		});
	});
	</script>
 
	</head>
	<body>
		<div id="redBox"></div>
		<a href="#">Show/Hide</a>
	</body>
</html>

In the tutorial I just used 2 of the more basic animation functions in the JQuery library. For a full reference to the JQuery animation API, please check out http://docs.jquery.com/Effects/. Stay tuned for JQuery part 3 :D .


Jul 3 2009

13 must have apps for Mac OS X developers

1. Apple Developer Tools – These are just a no-brainer here. There is a huge arsenal of apps that come standard with every mac that absolutely EVERY developer that is developing for mac os x needs. Xcode, Dashcode, Instruments, Interface Builder, etc. There are a ton more to check out if you haven’t already, and all of them will considerably ease your development experience on OS X.

2. Eclipse- Eclipse is the ideal application for java development on Mac OS X. With the amount of features that eclipse offers, it’s almost impossible to skip this application if you do any level of java development. The “intellisense” that eclipse includes while you’re coding is unprecedented.

3. Photoshop/ Gimp – This is a must have for any type of website development/interface development. Whether it’s doing website mockups or drawing new buttons for your application, this is a must have.

4. Coda – I can’t speak enough good things about coda. This application has exceeded my expectations in every way possible. Whether it’s through the handy “sites” feature, or connecting to a server using the built in console, this is by far the best web development app for Mac OS X. Well worth the 100 bucks!

5.uTorrent – A very simple torrent application. Extremely easy to use and very efficient. Having the ability to select which files you want to download and which you don’t is a huge bonus.

6. Adium – A very powerful messenger application for Mac OS X. From IRC plugins, to customizing the look and feel, Adium can pretty much do it all.

7. Jing – This screen capture application hides almost out of sight in your menu bar but packs some powerful features. Jing has the ability to capture screen casts of your applications in action as well as screen shots. Great App!

8. QT Creator – From the designer’s of the famous UI toolkit QT comes their first IDE. QT Creator is a fantastic IDE for developing QT Apps. From the WYSIWYG editor to the syntax editor, great app all around.

9. Prism – Pretty cool new(ish) app from Mozilla. This application allows you to capture sites like gmail and make them into a desktop application so you don’t have to open a browser every time you want to say check your email.

10. iStat Menu’s – This light-weight app will allow you to truly track your applications performance and see if you potentially have a memory leak in your app. Has a separate monitor for each CPU to allow the user to see what’s going on in each CPU at any given time. A must have even for non-developers.

11. XMind – This extremely powerful mind-mapping tool is great for those pre-alpha stages of development. Getting as many ideas down as quick as possible is extremely easy for this application to handle. The application is based on the eclipse platform and is very solid.

12. Virtual Box – This open source application is great for testing applications in numerous environments. Test run your apps on Linux, Windows, BSD and more.

13. VmWare Fusion – This is a must have for all developers but especially for those doing web development with coda. Allows you to run windows applications natively on Mac OS X. Another great app for testing in multiple environments as well.

Cheers