April 17, 2008 at 9:54 am
· Filed under JavaScript, Web
You may have heard of the Suckerfish Dropdowns featured on A List Apart (which use CSS and JavaScript along with valid HTML to create vertical or horizontal “drop-down” menus) and the the extended revised version Son of Suckerfish, but if you’re already using the jQuery library on your site the code to mimic the :hover pseudo-class gets even simpler.
Instead of:
1
2
3
4
5
6
7
8
9
10
11
12
13
| sfHover = function() {
var sfEls = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<sfels .length; i++)="" {="">
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
</sfels> |
You only need:
1
2
3
4
5
| jQuery('#nav li').hover(function(){
$(this).addClass('sfhover'); //mouseover
}, function(){
$(this).removeClass('sfhover'); //mouseout
}); |
Such is the beauty of using css-style selectors to build an array of affected elements. Of course, you must make sure the code is wrapped in $(document).ready(function(){…});, but there is no need to modify the window.onload event in this example. Otherwise, refer to the code provided in the above examples to get your markup and formatting styles in place.
Permalink
April 14, 2008 at 11:44 am
· Filed under Productivity, Web
My editor of choice lately has been Eclipse, even though I don’t know anything about Java. The PDT project for PHP development is wonderful for keeping track of variables and functions and classes that my site/application uses, and it has just enough panels that provide information about the projects that I am working on, as well as the attributes for just about every HTML/CSS element.
Coupled with Subclipse for Subversion source control, Eclipse is my one stop shop for all things web development.
My only problem is that I know I haven’t much scratched the surface of what it can do, or how it can help to simplify my workflow. I discovered the plugin library at EasyEclipse, but only experimented with a few of them; the HTML Tidy and webDAV + FTP plugins. I know that there are keywords and shorthand commands that can be entered to cut down on the entry of raw text, but I can’t seem to find a good resource for them.
If you use and love Eclipse, post a comment and share your resources about how it improves your workflow.
Permalink
April 14, 2008 at 10:21 am
· Filed under Productivity, Web
A number of code monkeys that I know use the Web Developer Toolbar in conjunction with the Firefox browser. The addition of a menu/toolbar is quite handy, especially the abilities to enable or disable JavaScript and CSS, and providing line guides and rules to ensure proper alignment of layout elements. Despite being so comprehensive in its features, it lacks the ability to view the loaded assets of a page, explore the DOM tree, or view box model for any element.
This is where Firebug comes in, allowing you to not only inspect an element with one click to reveal all of its defined and inherited styles and attributes, but also to edit the properties in the browser without having to make changes to the source documents.
With the most recent version of Firefox, I had issues with viewing the attributes and styles of the A element, but I found that an upgrade to beta version 1.1 solved the problem.
And for testing in Safari, Opera or dreaded Internet Explorer, they offer Firebug Lite that can be implemented via Javascript file to take advantage of the console object, which can be very useful for debugging JavaScript. I plan to write in further detail later about the wonder and majesty of this feature, so stay tuned.
If you enjoy the inspection aspect of Firebug, there is another cross-browser tool available called pi.debugger. It does not work with Safari (at least not version 3) but performs like a champ on IE, Camino and Flock. The script can be downloaded to your workspace or linked to from the Google source page in the link.
Given the number of options and resources available, the task of finding that one property that is throwing your whole layout off should be made that much easier. Happy hunting!
ADDITION: Westciv has released a slick bookmarklet called XRAY that lets you inspect elements in almost any browser.
Permalink