04.05

Techtopics: Week 1


My gtacm techtopics started last week. It’s all about javascript, jQuery, and AJAX. This week consisted of the introduction to the browser: DOM, DOM Inspectors, javascript: syntax, variables, jquery: syntax, selectors, basic animations.

You can download this week’s zip over at the techtopic page. It includes the html and javascript from our in class demonstration as well as another example, and the powerpoint i meant to show.

Here is some auxiliary stuff that I did not get to talk about in class but I wanted to cover.

$(document).ready(function(){})

All I said in class was that “this is necessary. Put everything inside here. jQuery won’t function without this. Don’t question”. I’m sorry, this was mean. What I really meant to explain was that this IS necessary, but it is NOT the only way to accomplish this task.

What this line is saying is that jQuery has some things that need to be run AFTER the browser has populated the DOM with all the HTML elements. It has to wait for this so that the elements EXIST when it tries to assign all the appropriate listeners to what you have told it to do. However, you can do this exact same thing with a much simpler call:

$(function(){})

That’s right, you can replace $(document).ready(fuction(){}) with $(function(){}).

Wow, that was easy.

Dropdown menu

I had originally planned on doing a full-blown example at the end of class. This example would be a dropdown menu that would work on hover over (similar to the one found at http://www.cc.gatech.edu). I have included it in the zip (found on the techtopic page) along with a spiffed up code that we did in class.

The dropdown menu included in the zip is a bare-bones implementation that you can put into any navigation. I used a function we didn’t cover in class .children(). Briefly, this function finds all the HTML elements that are contained in that element (div, span, etc), and you can refine it by putting a selector as a parameter to the function (like in my dropdown example).

Please study this and modify it (try using .fadeIn()/.fadeOut() instead of .slideDown()/.slideUp()) and try some experimentation with this. Also, this is a great reference to have in the future if you are building something that needs a dropdown menu: this will work great for you.

More Stuff

Two things I didn’t get to talk about this week are $(this) and .animate().

$(this) is a reference inside a callback function to whatever was selected. In the dropdown example, $(this) refers to the div with class=’hover-container’ that was hovered over. It only exists inside the callback function.

.animate() is the big kahuna when it comes to anything animated with jQuery. Actually, in the actual source code for jQuery most specifically named animation functions (slideDown, slideUp, etc) just call .animate() with the proper parameters for that specific function.

.animate() is ridiculously powerful and can do a lot of things. We will be covering it more in-depth in the final week.

Follow me on twitter: @helloandre


One Response to “Techtopics: Week 1”

  1. Tweets that mention Techtopics: Week 1 | andre bluehs -- Topsy.com Says:

    [...] This post was mentioned on Twitter by Andre Bluehs. Andre Bluehs said: new blog post about week 1 of my javascript/ajax class. http://ablu.us/cgr [...]

Leave a Reply