Events Entries
Monday, May 12th, 2008
Recently I have been getting a real buzz out of developing with jQuery. I’ve been using the library since 2006, releasing sporadic bits of code. In April of this year, I released the third revision of my most complex plugin, jMaps, and updated several other plugins, which are available in my mercurial repository.
This was also the same month I discovered a new plugin which has dramatically changed how I develop applications with jQuery. The plugin in question is Dan Webb’s Low Pro for jQuery, a port of the plugin of the same name for Prototype.
What is Low Pro?
So what is Low Pro? It’s a plugin that provides a way of making more object-oriented JavaScript through event delegation. jQuery’s plugin architecture provides a really simple way of extending the core functionality, but there is no easy way of making macros of code that do several types of events on one element. Until now!
(more…)
Posted in DOM Modification, Events, Intermediate, Plugins, jQuery | 13 Comments »
Monday, March 31st, 2008
CSS and JavaScript are different in many ways, almost all of which are too obvious to mention. However, one difference between the two bears explanation, because it is often the cause of confusion and consternation, especially among those who are making the transition from CSS guru to jQuery novice. In fact, it was one of the first things I asked about on the jQuery mailing list back in 2006. Since then, I’ve seen at least one question on the subject every week, and sometimes as many as one per day—despite an FAQ page and these three plugins to help users deal with it.
How CSS and JavaScript Are Different
So, what’s this important difference?
(more…)
Posted in Beginner, DOM Modification, Events, Intermediate, jQuery | 30 Comments »
Saturday, October 20th, 2007
After posting the last entry on animated scrolling with jQuery 1.2, I realized that I had left out an important piece of code. Actually, I didn't discover it until someone notified me that another page on the site was broken. Can you spot the problem(s)? [Note: the problem is not in line 3. The syntax highlighter just can't handle the regular expression with two slashes in it ("//") and is incorrectly treating them as a comment mark.] See the answer below the code.
JavaScript:
-
$
(document
).
ready(function(){
-
$
('a[href*=#]').
click(function() {
-
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
-
&& location.hostname == this.hostname) {
-
var $target = $(this.hash);
-
$target = $target.
length && $target
-
|| $
('[name=' +
this.
hash.
slice(1) +
']');
-
-
var targetOffset = $target.offset().top;
-
$('html,body')
-
.
animate({scrollTop: targetOffset
},
1000);
-
return false;
-
}
-
}
-
});
-
});
(more...)
Posted in Beginner, Effects, Events, Intermediate, jQuery | 26 Comments »
Thursday, September 20th, 2007
A common pattern in jQuery plugin development is the need to undo what the plugin has done. This is usually handled through a method prefixed with "un". Another common pattern is the use of anonymous functions for event handlers. Unbinding events is easy with jQuery but unbinding a single event handler requires the use of a named function. jQuery 1.2 now provides another option for binding and unbinding events: event namespaces.
(more...)
Posted in Events, Intermediate, Plugins, jQuery | 8 Comments »
Saturday, February 17th, 2007
Sometimes it's nice to be able to give users visual feedback when they hover their mouse over an element on the page. It's easy to do, of course, with a little CSS:
#hover-demo1 p:hover { background: #ff0; }
That little style rule changes the background of any paragraph that is a descendant of an element with id="hover-demo" to a nice bright yellow — but only when you hover your mouse over it. So, if that's all there is to it, what does this have to do with jQuery?
(more...)
Posted in Beginner, Events, jQuery | 34 Comments »
Thursday, February 8th, 2007
We've received a number of comments recently from people looking for variations on the showing and hiding theme. For the basics, you can take a look at two earlier entries, Basic Show and Hide and Slicker Show and Hide.
For a full-blown plugin solution with lots of options, look no further than Jörn Zaefferer's Accordion Menu. But if you want to try some showing and hiding on your own, read on.
(more...)
Posted in Beginner, Effects, Events, jQuery | 141 Comments »