jQuery

Basic jQuery Tutorial: Modify CSS classes and attributes, Hover and Toggle example

Wednesday, June 16th, 2010 | Tutorials | 4 Comments

This tutorial will cover:

  • Modifying CSS attributes with jQuery
  • Setting a class for a page element
  • Removing a class from a page element
  • Testing if a class exists
  • A quick toggle click behavior example

The final example will use all of the other elements in a single exercise.

› Continue reading

Tags: , , , , , , , , , , , , ,

Web Developers: How to develop for iPhone / iPad / iPod Mobile Safari

Thursday, June 10th, 2010 | Business | 6 Comments

In short, don’t.  It’s an uphill fight.

There are a few obstacles in developing for the iPhone / iPad I thought I’d post while it was on my mind:

  • How can I test my “mobile” site?
  • How can I see errors on my iPhone?
  • Why is the iPad and iPhone different?

Basically Apple has decided to make life difficult for web developers.  This was ideally done to improve the user experience on their mobile platforms, but I don’t think it was fully thought out.

› Continue reading

Tags: , , , , , , , , , , , ,

Google Code: Did they break jQuery on some sites?

Thursday, June 3rd, 2010 | Business | 2 Comments

I was sitting around developing some code for a website yesterday (June 2, 2010) and my jQuery started to break.  It was after I had taken a break, and knew it worked beforehand.

When I looked into the problem I saw that the Google Code loaded jQuery 1.4.2 had a problem.  It wasn’t loading properly!

› Continue reading

Tags: ,

HTML Zen Coding: Speed up HTML creation

Tuesday, May 4th, 2010 | Business | 2 Comments

HTML Zen Coding is a plugin for many popular HTML editors that gives the web developer many tools for quickly building out HTML pages.  If you are comfortable (and enjoy) CSS selectors popular today in many frameworks (such as jQuery) then this may be for you.

When we build HTML documents, we are always building code that is repetitive, and we have ways of making that better.  Creative copying and pasting usually.  Sometimes I feel like I’m playing music on my keyboard when I do my copy paste and edit keyboards commands over and over.

With Zen Coding the process is much “simpler”.  You need to learn the syntax, which is straightforward for most selector friendly folks — but it will shorten your workload and let you do some things that you may have avoided before.

› Continue reading

Tags: , , , , , , , , , , , , , , , , ,

HTML 5 Presentation on HTML5

Saturday, April 17th, 2010 | Business | No Comments

Saw a great HTML5 presentation today at Apirocks.com: HTML5 Presentation.  Has tons of useful demos of new HTML5 technologies that you can actually USE TODAY.

› Continue reading

Tags: , , , , , , ,

HTML Fadein Fadeout: Basic Javascript/AJAX Tutorial using jQuery’s fadeTo

Tuesday, April 13th, 2010 | Business, Tutorials | 4 Comments

In this tutorial we will review:

  • Basic document jQuery preparation
  • Binding  jQuery actions to an anchor (A) tag
  • Fading In and Fading Out html elements with Javascript/AJAX

› Continue reading

Tags: , , , , , , , , ,

Help: IE7 won’t load my JSON but IE8 will – Using a JSON Validator

Monday, March 8th, 2010 | Business | 2 Comments

I just ran into this issue, and found surprisingly little documentation.  My JSON request wasn’t returning.  I was using the jQuery “getJSON” method to send the request out.  Nothing was coming back.

› Continue reading

Tags: , , , , , , , , , ,

Basic AJAX Tutorial: Smooth Scrolling Text Marquee with a jQuery plugin

Monday, January 26th, 2009 | Business, Tutorials | 72 Comments

This tutorial covers:

  • What is a plugin?
  • Installing a plugin
  • The jQuery Marquee plugin
  • Implementing the jQuery Marquee plugin

What is a plugin?
A plugin is an addition to the core jQuery functionality.  Plugins are made to be simply integrated into an existing jQuery web page.

For this tutorial, we will be working with the jQuery Marquee plugin from remy sharp’s b: log.  Take a look, he did a good job putting his post together.





Installing a plugin
Installing plugins is very easy.  This is the easiest part of working with all plugins.

Pretty much:

  1. Download the plugin
  2. Upload the plugin to your server
  3. Include the plugin in your document

First, download the jQuery Marquee plugin here (taken from the original post, The Silky Smooth Marquee).  If it just displays in your browser, right click on the link and select “Save Link As…”.

Now that we have the plugin, we just need to post it on our site.  Upload it to your javascript folder (I normally use “/js” for this).

Finally we need to include the JS library in your document, so we add the following line (into a very basic document):

<html>
<head>
     <script language="javascript" src="js/jquery.js"></script>
     <script language="javascript" src="js/jquery.marquee.js"></script>
</head>
<body>

</body>
</html>

It’s uploaded!

The jQuery Marquee plugin
Whenever working with a plugin, normally the plugin page has helpful instructions on it’s use, and examples.  In this case that is true.

Again, I’m going to link back to the original page — The Silky Smooth Marquee.

On that page the author has detailed:

  • Demo
  • Download
  • Usage
  • How it works
  • Events
  • Support

Very helpful.  Additionally, it helps to look and see if there are any useful comments.  Usually commenters point out minor flaws in the code posted (or major!), and supply resolutions.  If you follow the conversation thread on the post, you will see commenters have requested functionality that was implemented back into the plugin.

Implementing the jQuery Marquee plugin
Now the final part.  This is both easy and hard.  The easy part is usually getting the basic implementation working.  The hard part comes in when you try to do exactly what YOU want to do with THEIR plugin example.  Usually it can be done.  Sometimes there are minor modifications that have to be made to the original plugin.

Once you have added the library, all you need to do is include the code.  There is a great example page, jQuery Marquee Demo, that shows the various implementations.

For our purposes we’ll implement a basic marquee on our page:

<html>
<head>
     <script language="javascript" src="js/jquery.js"></script>
     <script language="javascript" src="js/jquery.marquee.js"></script>
</head>
<body>
     <marquee behavior="scroll" direction="up" scrollamount="1"
          height="75" width="150">
          <p>This is a test of a Smooth Marquee using jquery.</p>
          <p>This is a test of a Smooth Marquee using jquery.</p>
          <p>This is a test of a Smooth Marquee using jquery.</p>
     </marquee>
</body>
</html>

The plugin automatically binds to the marquee tag.  Does yours work?  Check out our example of jQuery scrolling text marquee.

That was too easy?

Yes.  If you look at the comments, one common request is to adjust the scroll speed.  You can see that our scrollamount is already set to the minimum, 1.

The author recommended setting the timeout (refresh rate) to a larger number.  By default, it is set to 25ms.  If we wanted to go twice as slow, we just have to change that to 50ms.  This is where modifying the core code of the plugin comes in.  If you want to go ahead and do this:

  1. Open up the jquery.marquee.js file.
  2. Find the line: “setTimeout(animateMarquee, 25);”
  3. Change it to: “setTimeout(animateMarquee, 50);”
  4. Upload the new jquery.marquee.js file

The sky is the limit.

Please give us feedback on this tutorial, also take some time to thank the author of this plugin, Remy he’d probably appreciate a follow on Twitter, or even a comment on his blog.

Tags: , , , , , , ,

Basic AJAX Tutorial: jQuery toggle and slide

Wednesday, January 21st, 2009 | Business, Tutorials | 20 Comments

In this tutorial we will review:

  • Definition of AJAX
  • Introduction to jQuery
  • Basic document jQuery preparation
  • Binding jQuery actions to an anchor (A) tag
  • Toggling visibility of a div
  • Sliding in and out of that div

It sounds like a lot, but it’s all very easy.

Definition of AJAX
The term AJAX means Asynchronous JavaScript and XML.  That means AJAX technically defines a method for javascript to communicate with XML.  Over the past few years AJAX has been interpreted as a means for implementing all “web 2.0″ functionality in the front end.  That added things like animations to the general term “AJAX”.





Introduction to jQuery
jQuery is one of my favorite libraries with a good toolset for working with AJAX techniques.  You can find out more information on jQuery at their site.

jQuery is a “fast and concise Javascript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development”.  Taken from the website itself.

As a javascript library, we will have to include the jQuery library on a page, and implement some of it’s more basic functions.

Basic jQuery document preparation
The first thing we need to do is incorporate the jQuery library in our page.  So download jQuery (direct link to the Google Code location).

Now that we have our JS library, we need to tell our document where it is (I renamed my js file to jquery.js, and threw it in the js folder):

<html>
<head>
     <script language="javascript" src="js/jquery.js"></script>
</head>
<body>

</body>
</html>

We inserted the SCRIPT tag to include the jquery library when the page is loaded.

Binding jQuery actions to an anchor (A) tag
Lets create a basic link in our document:

<html>
<head>
     <script language="javascript" src="js/jquery.js"></script>
</head>
<body>
     <a href="#">Click Here</a>
</body>
</html>

We now have a link that does nothing.  We are preparing to bind jQuery to the anchor.

Toggling the visibility of a div
We need to do 2 things to toggle the visibility of a div with jQuery.  First off, we need a DIV to toggle!  Second we need to bind jQuery commands to the anchor link.

We will take advantage of the jQuery toggle effect.

To do this, we change our code below:

<html>
<head>
     <script language="javascript" src="js/jquery.js"></script>
     <script language="javascript">
     $(document).ready(function() {
          $('#toggleButton').click(function() {
               $('#toggleSection').toggle();
               return false;
          });
     });
     </script>
</head>
<body>
     <a href="#" id="toggleButton">Click Here</a>
     <div id="toggleSection">
          Content to toggle on and off
     </div>
</body>
</html>

This step we did a lot.

First we added [id=”togglebutton”] to the A tag.  That lets us identify it in the jQuery code.

Second we added the “toggleSection” DIV to the document.  The entire div will be toggled on and off.  Again, here we identified the DIV as “toggleSection” to be able to target it with the jQuery code.

Third, we added the jQuery code that actually does the toggling in the HEAD section of the document.  jQuery is a javascript engine, so we have to execute the commands in SCRIPT tags.  The first line of the code, “$(document).ready(function() {” is complicated.  Lets dissect this code.

Finally we put “return false;” in the code, that tells the link NOT to use the HREF value.  This means “#” will not be loaded.  It’s annoying, because that brings the browser to the top of the page in certain browsers.

$(document) — this is the HTML document itself.  It is the same as “document” in normal javascript.

.ready( — this is us looking at the “onLoad” part of jQuery.  When the document is ready, it executes  the “ready” method.  Here we are defining what the ready method is.

function () { — basically, we are creating a new function that will fill in for the document.ready method.  When the document is ready, our code will be executed.  This is smart, as executing code when the page isn’t ready can result in missing elements that aren’t loaded yet.

After that statement, we have “$(‘#toggleButton’).click(function() {“, another complicated statement.  Lets break it down:

$(‘#toggleButton’) — we are looking for the “toggleButton” via jQuery.  This code finds it for us.

.click( — Instead of setting the value of the “ready” method before, we are setting the function of when the “toggleButton” is clicked. So we need to create a function…

function () { — again, creating a function inline.  This will be assigned to the button’s “click” method.

Finally we do the fun stuff, toggling the DIV on and off with “$(‘#toggleSection’).toggle();”.  By now it should be easier to read this line.  We are finding the toggleSection div, and calling the jQuery method of “toggle()” which will toggle the visibility of the DIV.

It is important to note the “return false” part of this.  By returning false, we are telling the HREF that it should NOT execute the HREF value (which is #, and would bring the browser to the top of the screen).  If we don’t return false, the browser will still load the HREF value, and we will have some minor issue cross browser.

We’re done!  We are toggling the visibility, check out the demo — jQuery toggle demo.  Fortunately, we can still have a little more fun..

Sliding in and out of that div
In the previous step, we toggled the visibility of a DIV.  It’s not too exciting, as we could easily do that with javascript before with stylesheets and basic DOM code.  What is great about the jQuery library is all of the additional methods for animation it gives us.  Lets setup that div to not just appear, or hide — but to slide in and slide out.

For that we will take advantage of the slideUp and slideDown methods, they are just 2 of many Effects available in jQuery.

<html>
<head>
     <script language="javascript" src="js/jquery.js"></script>
     <script language="javascript">
     $(document).ready(function() {
          $('#toggleButton').click(function() {
               if ($('#toggleSection').is(":hidden"))
               {
                    $('#toggleSection').slideDown("slow");
               } else {
                    $('#toggleSection').slideUp("slow");
               }
               return false;
          });
     });
     </script>
</head>
<body>
     <a href="#" id="toggleButton">Click Here</a>
     <div id="toggleSection">
          Content to toggle on and off<br>
          More content<br>
          Slides are more fun with more content<br>
          Four lines should be enough
     </div>
</body>
</html>

We have added a little more content to the DIV, so we can more easily see how the slideUp and slideDown work.  There are 2 interesting steps we hav taken.

First, we added an “if” statement to detect if the DIV is hidden or not.

Second, we added code to slideUp or slideDown depending on whether the DIV is actually hidden.

Check out the result on our example — jQuery slideUp and slideDown demo.

Conclusion
I hope this helped some of you out.  Let me know if it did.  Comments are open!

Tags: , , , , , , , , , , , , ,

jQuery 1.3 Released – How to use jQuery

Thursday, January 15th, 2009 | Business | 10 Comments

jQuery is a “fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development.  jQuery is designed to change the way that you write JavaScript.”

jQuery version 1.3 was released yesterday.

Some new features in 1.3 are:

  • Sizzle – a brand new CSS selector engine
  • Live Events – event delegation with a jQuery twist
  • jQuery Event Overhaul – simplified event handling
  • HTML Injection Rewrite – Lightning-fast HTML appending
  • Offset Rewrite – Super-quick position calculation
  • No more browser sniffing!!
  • New API Browser – http://api.jquery.com/

I have yet to play with jQuery 1.3, but will post my impressions after I get some hands on time with it.

Are you new to jQuery?
jQuery is a library that you can include on your web projects.  jQuery enables HTML and JavaScript developers to rapidly deploy functionality that traditionally is more complex.  Through browser independent APIs, developers and designers can implement event handling, CSS changes, animations, popular web 2.0 effects, or other common function of web 2.0+ sites. 

Downloading jQuery
You can get jQuery by going to jQuery.com and downloading the version of jQuery you want:

  • Production version – 18kb – Minified for production environments (don’t try to debug this, its a nightmare)
  • Development version – 114kb – Developers can go in and see how things work with this version, but the footprint is huge

Getting Started with jQuery
jQuery provides a series of useful tutorials.   

Some favorites are:

There are so many more tutorials out there.

Tags: , , , , , , , , , , , , , , ,


Please share, it makes me happy:

Subscribe to Email Alerts

Follow Me

Follow seangw on twitter

Archives

Categories

prestashop theme

virtuemart template