Adding attributes to elements using jQuery

June 10th, 2010

As promised in yesterday’s post, today I am going to show you how to add id’s to a bunch of elements. Everyone has created navigation menus using unordered lists. Very common thing right? Well, sometimes you have to actually style every list item or ‘a’ tag differently. I’m going to show you to use jQuery to add a different id to each list item in a typical navigation. So first, I’ll give you the simple html:

<ul id="navigation">
<li><a href="index.php">Home</li>
<li><a href="about.php">About</li>
<li><a href="portfolio.php">Portfolio</li>
<li><a href="contact.php">Contact</li>
<li><a href="/blog">Blog</li>
</ul>

Pretty straight forward list. Here is the jQuery:

$(document).ready(function() {
    $('#navigation li').each(function(index) {
     $(this).attr({
        'id': 'nav-' + index
     });
  });
});

That finds every li within the ul with an id of ‘navigation’, and for each of them give it an id of ‘nav-’ and whatever number it is in the index. So the first li in the list would have an id of ‘nav-0′. Since the index starts at 0. Now that you know how to do that, you can add any attribute you want to anything, be it a title, an href, its all up to you. Hop to it.

Coupon Code: webmachine

jQuery junkBox

$.merge(firstArray, secondArray);
This merges the contents of the second array into the first. So the below code would print out: 0, 1, 2, 3, 4

var firstArray = [0, 1, 2];
var secondArray = [3, 4];
var finalArray = $.merge(firstArray, secondArray);
$.print(finalArray);

Inserting new elements with jQuery…and a CSS3 tip!

June 9th, 2010

Let’s start with a cool ass CSS3 tip. I can’t claim credit for this, as I just watched a video of it over at Nettuts+, done by Jeffery Way (my favorite tutorial creator), which you can watch here if you want. But it is really simple, so I’ll give you the gist of it right here.

Ever do image reflections? If you build enough sites, you most likely have. You know what I’m talking about, right? You have an image, and a copy of the image is flipped vertical below it and faded out so it looks like it is a mirror image? Well, you can do that using only CSS3 now, but be aware, as of right now, it only works in Safari and Chrome. I really hope this one gets to Firefox soon, because I have to do this effect often enough where this would make it easy. Here is the CSS:

-webkit-box-reflect: below 4px - webkit-gradient(linear, left top, left bottom, from(transparent), color-stop(.7, transparent), to(white));

This is all one style, meaning it is not divided into multiple lines. You would put this on an image, and here is what all that crazy does. Obviously it reflects the image, below the original with a 4px gap between them. Adds a linear gradient to the reflection from top to bottom, starting with no color (transparent) and going to white. The color-stop number is how much the reflection shows. And that is it! This is actually one “cool” effect that I actually have a use for. Congrats to Safari/Chrome for getting this into their browsers…now get Firefox on the job.

Now, on to the jQuery!

Read the rest of this entry »

How to change Photoshop’s Keyboard Shortcuts, and write an Action

June 8th, 2010

A commenter here at The Web Machine has asked me to show how to change Photoshop’s Keyboard Shortcuts, which I talked about in my last post. So, since it was a request, how can I refuse. It is actually quite simple really. I’ve gathered some screen shots to walk you through it.

First, go to the Edit menu and select Keyboard Shorcuts (or Alt+Shift+Ctrl+K if you want the Keyboard Kung-Fu method). Figure 1 shows the window that will pop up. On the left hand side you sill see Application Menu Command, and under it, all the menu items in Photoshop. If you click on the arrows next to them, you will see all the sub menus under each main menu. Those sub menus will show the shortcut keys to the right, if they have one.

figure 1

Read the rest of this entry »

Creating your own web dev tool kit – Part II: Being fast

June 4th, 2010

In my Part I post, I talked about having a base CSS starting file and an HTML/PHP/Whatever file. This helps you do things quickly that would normally take time to set up. But what else is there that can spead up your process in getting a site done quickly?

Keyboard Kung-fu

Plenty, I say, plenty. Most of them little. It used to be, back in the day, that Photoshop didn’t allow you to edit your keyboard shortcuts. I use to have a huge Action file that did all sorts of things like flatten layers, change color modes, aligning things with a push of a button, stuff like that. Now though, PS allows you to customize the keyboard shortcut preferences. I have a ton of my rearranged. For instance, to flatten layers, I just have to hit F2, to change to RGB mode for when I get something that is in CMYK or when I open a gif, I just hit Ctrl + R, and bingo, RGB mode.

Doesn’t seem like much, but think of all of things you do in Photoshop…and I mean things you do all the time. Wouldn’t it be nice to just hit a button and presto that is done? I know this sounds stupidly easy, but I am still amazed by how many new developers keep going to the damn menus to do simple things. Maybe they are scared to overwrite the shortcuts that PS has by default. Well, they shouldn’t.

Read the rest of this entry »

Test driving Sass 3…a second look at Sass

June 2nd, 2010

Sass logoSoooo…I have decided to try my hand at updating my install of Sass to version 3. I’m just a simple cave man…but I do know one thing. THAT was a bitch. I am stupid when it comes to command-line stuff. I literally have to do a google search on everything that I try to do. I have 10 windows open at the moment and each one is something dumb. Like how to change directories, how to update a damn gem, how do I update compass, how do I recompile with compass….COME ON!

Whew! Its done. And it works. Thank GOD! Now first I am going to give you a link to the test page I am building (using the html from my “Creating your own tool kit – Part I: CSS” post).

Click here for the demo.

Let’s take a look at the Sass first. Keep in mind, this is basic Sass stuff, but I want you to see the cool factor. Sass 3′s main syntax is SCSS (Sassy CSS). It is more closely related to CSS than Sass 2 was.

NOTE: I wrote an article a while back about Sass, but that was using version two’s syntax, so I am basically starting over.

Read the rest of this entry »