Robots Rule | MindSculpt.net

New media has met its match.

The MindSculpt Design Syndicate focuses on code that works, from CSS, XHTML and JavaScript tips and tutorials to Flash and ActionScript how-to's. Robots not included.

Archive for November 2009


CSS Tips and Tricks for Internet Explorer 6: Cross Browser Support for Styles

November 23rd, 2009 — 10:00am

Internet Explorer 6 is the bane of any web developer’s existence. Unfortunately it still has a grasp on the browser market share. And when you’re doing work for law firms, pharmaceutical companies, or any industry whose target customers are more likely to have older equipment, those few people who still use IE6 become pretty important. Fortunately it’s not that hard to make a website that looks almost identical across every browser. Here are my list of fixes for the most common style related problems I’ve come across while testing in IE6.

  • In IE6 the margins are doubled for elements that are floated and have right or left margins. To fix this simply add display: inline to the styles of that element.
  • PNG transparency is not natively supported in IE6, but sometimes you need images that have feathered transparency. Use the script found here to solve this: http://www.twinhelix.com/css/iepngfix/
  • Sometimes absolutely positioned elements that are next to each other in the HTML will disappear in IE6. Surround each with a dummy <div> tag to fix this. See this link for more info: http://www.brunildo.org/test/IE_raf3.html
  • When using z-index, logically you would apply the higher index on the element you want above and a lower index on the element you want below. However in IE6 you need to put the higher z-index on the containing block otherwise you may run into issues. So if you have a main container, and a nav container with a <ul> and you want the <ul> on top (for example if you were making a drop down) put the higher z-index on the nav container, not the <ul> itself.
  • You may notice a <div> with a small height that has no margins or padding has an extra margin under it or is larger than the specified height. Set the <div> styles to font-size: 1px; to fix this. If the <div> needs to be one pixel high, you may not be able to get the font small enough. Instead, try using a 1px border on the <div> to achieve the desired effect.
  • Use this resource to view how a page looks in different browsers. It only returns a screenshot so there is no functionality, but it can be helpful just to see how the static layouts are flowing: http://ipinfo.info/netrenderer/
  • Looking to get fixed positioning to work in IE6? Try this solution here: http://ryanfait.com/position-fixed-ie6/
  • You can download a standalone version of IE6 for testing from here: http://browsers.evolt.org/?ie/win32/standalone (click “ie6eolas_nt.zip” to download). When I tried to run this through Parallels on my mac, I couldn’t get it to connect to the internet, but comments in other forums suggest that it does in fact work. At the very least you can test local files this way.

Share your tips and tricks in the comments.

Share this post:
  • Twitter
  • Facebook
  • del.icio.us
  • Digg
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Technorati
  • Google Bookmarks
  • Yahoo! Buzz

Comment » | CSS, HTML

The lost arts of Flash part 1: Commenting

November 12th, 2009 — 11:13am

Becoming proficient in programming ActionScript in Flash takes more than spewing object-oriented buzzwords and writing complex classes only decipherable to elite Flash geeks. In my opinion, there are three lost arts in Flash programming; in this article we’ll talk briefly about commenting.

How could such fundamental techniques as these actually be on the verge of extinction, you ask? The answer is obvious: Amidst the daily whirlwind of demanding clients and looming project deadlines, it’s easier (and faster) to code projects without taking the time to include explanations for each line of code you type.

The reality however, is this: The time you take up front to properly comment your code and add meaningful trace statements within your ActionScript, the more time that will be saved when you revisit this file in 2 weeks, 2 months or 2 years. It also serves as the key to other developers who may need to jump in on your project or make updates in your absence. If you’re already commenting your code, I applaud you and grant you the permission to skip the rest of this article and spread the gospel.

Commenting Your Code
Commenting your ActionScript should be second-nature. It’s probably the easiest element you can contribute to your Flash application. There are countless techniques and preferences on how commenting should be formatted. The most important aspect of commenting is that you are clear and concise, so that your functionality will make sense to someone else (and even yourself) later down the road. Comment every variable, function and loop in your application so it reads fluently as a step-by-step guide to how your brain works. Also make sure you use variable and function names that make sense (one of the ‘lost arts’ to be covered in a subsequent article).

While programming your app, it’s helpful to keep the following in mind:

  • Will someone else be able to understand how I programmed this app?
  • In 2 weeks (months, years), will I be able to understand how I programmed this app?

Wow, that’s a short list. That’s because commenting should be an integral part of your workflow. Taking the extra time to type a few comments will save you (or someone else) their time and their sanity, and make you look like a well-balanced, ‘big picture’ oriented Flash programmer.

Share this post:
  • Twitter
  • Facebook
  • del.icio.us
  • Digg
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Technorati
  • Google Bookmarks
  • Yahoo! Buzz

Comment » | Flash AS2, Flash AS3

jQuery Animated Rollover Drop Down Navigation

November 10th, 2009 — 11:10am

This article will demonstrate how to create an animated rollover drop down menu using HTML, CSS, and jQuery. Take a look at the demo to see the final result, or download the files directly.

Tested on
PC: IE6-8, Firefox; Mac: Safari, Firefox, Opera

HTML Structure

  1. <div id="nav">
  2. <ul id="nav1" class="menu_body">
  3.    <li class="menu_head"><a href="#">Nav Header 1</a></li>
  4.    <li><a href="#">Nav Item 1</a></li>
  5.    <li><a href="#">Nav Item 2</a></li>
  6.    <li><a href="#">Nav Item 3</a></li>
  7.    <li><a href="#">Nav Item 4</a></li>
  8.    <li><a href="#">Nav Item 5</a></li>
  9.    <li><a href="#">Nav Item 6</a></li>
  10. </ul>
  11. … nav2 …
  12. … nav3 …
  13. … etc …
  14. </div>

Each navigation menu is a list that sits inside a div with the ID nav. Give the list a class of menu_body and an id of nav1 for the first one, nav2 for the second, and so on. The naming here is important not only for the styles, but because the jQuery functions look for the “nav#” items. Also, give the first list item the class of menu_head. This is the item that will remain when the navigation is collapsed. Giving it a class will allow you to style it differently if necessary.

Styles

  1. /* Nav */
  2.  
  3. #nav {
  4.    float: left;
  5.    width: 480px;
  6.    height: 21px;
  7.    display: inline;
  8.    margin: 10px;
  9. }
  10. #nav ul {
  11.    float: left;
  12.    width: 160px;
  13.    margin: 0;
  14.    padding: 0;
  15.    overflow: hidden;
  16.    list-style-type: none;
  17.    visibility: hidden;
  18.    background: #00a95c;
  19. }
  20. #nav li {
  21.    float: left;
  22. }
  23. #nav a {
  24.    float: left;
  25.    width: 160px;
  26.    color: #fff;
  27.    text-decoration: none;
  28.    display: block;
  29.    margin: 0;
  30.    padding: 8px 0 8px 20px;
  31.    font-size: 14px;
  32. }
  33. #nav ul a:hover {
  34.    font-weight: bold;
  35.    background: url(subnav_arrow1.gif) 10px 50% no-repeat;
  36. }
  37.  
  38. #nav li.menu_head a {
  39.    padding: 2px 0 0 6px;
  40.    padding-bottom: 10px;
  41. }
  42. #nav li.menu_head a:hover {
  43.    background: none;
  44. }

The styles is what you’ll want to start customizing for your needs. You’ll want to update the #nav with the width and height of your navigation bar. This is the container for the whole navigation so you can change margins or positioning as needed.

Next you’ll want to update the width in the #nav ul section. This is the width of the nav item in the menu as well as the drop down. You’ll probably want to change the background color too. You’ll notice that the visibility is set to hidden. The reason why will be explained in the jQuery section.

Setting #nav li to float left fixes a bug in IE6 that adds extra spacing between each list item.

Again, change the width in #nav a to the same as the width you changed in #nav ul. Adjust color, padding, etc as needed.

#nav ul a:hover adds the rollovers effects to the each navigation link, and #nav li.menu_head a and #nav li.menu_head a:hover override those styles so you can change the behavior of the first navigation item.

jQuery Functions

  1. $(document).ready(function () {
  2.  
  3.    var startingHeight = 21; // Specifies the height of your navigation when collapsed
  4.    var speed = 300; // Specifies the speed of the animation
  5.  
  6.    var heights = new Array();
  7.  
  8.    var i = 1;
  9.    while ($("#nav"+i).length) {
  10.       heights.push($("#nav"+i).height() + 8);
  11.       $("#nav"+i).height(startingHeight);
  12.       $("#nav"+i).mouseover(function () {
  13.          $(this).stop().animate({height:heights[this.id.substr(3)-1]},{queue:false, duration:speed});
  14.       });
  15.       $("#nav"+i).mouseout(function () {
  16.          $(this).stop().animate({height:startingHeight+‘px’}, {queue:false, duration:speed});
  17.       });
  18.       i++;
  19.    }
  20.  
  21.    $("#nav ul").css("visibility", "visible");
  22.  
  23. });

You should only need to modify 2 variables in this file unless you want to customize the functionality. startingHeight should equal the height of your #nav div. This is the height that the mouseovers will return to on mouseout. The speed controls how fast the animation runs and can either be one of the jQuery standard strings “slow,” “normal,” or “fast” or a number in milliseconds.

When I initially created this I came across a problem where the lists would have slightly different heights in different browsers. However, since I am animating the heights I needed to know those specific values. I initially tried solving this this by having the navigation start fully open, grabbing the heights of each list and setting the heights back to the value for the collapsed nav. This worked, however there was sometimes a flicker when the page first loaded. Especially if the load time was longer on a slower connection. The solution to this was to set the style of the lists to visibility: hidden which hides the navigation from view but unlike display: none keeps the space that the item take up. So I could grab those heights (the “+8” adds 8 extra pixels to the bottom for extra padding) without anybody seeing the list, reset the heights to collapsed, and once that is finished turn the visibility back on. That’s what the first two lines in the loop do. They add the current height to an array.

The loop starts at the id nav1 and loops through and increments until it finds one that doesn’t exist. It’s important to start the nav’s at 1 and keep them consecutive. The .length attribute returns 0 if an item does not exist ending the loop.

The next section in the loop applies the mouseover and mouseout functions. This applies a stop and and animate function. If you remove the stop and the queue attributes and then test the rollovers a few times you’ll see why. By default jQuery queues animation. The stop in combination with the queue: false prevents this from happening.

The height that it’s using is grabbed from the array by pulling out the number from the “nav#” id. This was the best way I could think of doing it, because I couldn’t figure out how to pass the dynamic variable “i” into the mouseover. If there’s a way to do this let me know in the comments. The mouseout simply returns the list to the original height.

Finally after all of this is set up, the visibility is turned back on. Let us know in the comments if you use this for your website.

Tips:

  • Style each menu differently by targeting them with #nav1 etc. in the CSS.
  • Replace the text in the menu_head with an image for a graphical navigation.
Share this post:
  • Twitter
  • Facebook
  • del.icio.us
  • Digg
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Technorati
  • Google Bookmarks
  • Yahoo! Buzz

2 comments » | CSS, HTML, JavaScript, jQuery

Back to top