MooTools Archives

Google-Style Element Fading Using MooTools or jQuery

Published by David Walsh on Monday, February 1, 201038 Comments

Google Homepage

Google recently introduced an interesting effect to their homepage: the top left and top right navigation items don’t display until you move your mouse or leave the search term box. Why? I can only speculate that they want their homepage as simple as possible; after all, the search box is given focus immediately and at least half of their users probably just type their term and hit enter — no need for more clutter. Here’s how you can implement a similar system with MooTools or jQuery.

Drag and Drop Z-Index Stacking

Published by David Walsh on Friday, January 29, 201028 Comments
MooTools Drag Opacity

In an example for a previous post, I showed you how to use opacity during a drag’n'drop transaction. One bit I didn’t account for was element stacking and bringing the most recent element to the top of the stack. To do so, we’ll need to use a variable that represents the highest zIndex, which we’ll be incrementing.

The MooTools Javascript

window.addEvent('domready',function() {
	var zIndex = 2;
	$$('.draggable').each(function(el) {
		var drag = new Drag.Move(el,{
			grid: false,
			preventDefault: true,
			onStart: function() {
				el.setStyle('z-index',zIndex++); //increment!
			}
		});
	});
});

As you probably expected, the process is as simple as it gets. Correct stacking order is incredibly important as you don’t want items to be wrongly buried.

Printing MooTools Accordion Items

Published by David Walsh on Wednesday, January 27, 20109 Comments
MooTools Accordion

Sometimes we’re presented with unforeseen problems when it comes to our javascript effects. In this case, I’m talking about printing jQuery and MooTools accordions. Each “closed” accordion content element has its height set to 0 which means it will be hidden when the user tries to print the page. Luckily MooTools Core Developer Thomas Aylott provides a simple fix.

The CSS Fix

@media print {
	.element { height:auto !important; }
}

That’s it — no joke. Setting a print-specific height of auto with the ever-useful !important declaration fixes everything.

Sliding Labels Using MooTools

Published by David Walsh on Monday, January 25, 201047 Comments

A week back I saw a great effect created by CSSKarma: input labels being animated horizontally. The idea is everything positive: elegant, practical, unobtrusive, and requires very little jQuery code. Luckily the effect doesn’t require much MooTools code either!

The HTML

<form action="" method="post" id="info">
	<h2>Contact Information</h2>
    <div id="name-wrap" class="slider">
        <label for="name">Name</label>
        <input type="text" id="name" name="name">

    </div><!--/#name-wrap-->

    <div id="email-wrap"  class="slider">
        <label for="email">Email</label>
        <input type="text" id="email" name="email" />
    </div><!--/#email-wrap-->

    <div id="street-wrap"  class="slider">
        <label for="st">Street</label>

        <input type="text" id="st" name="st" />
    </div><!--/#street-wrap-->

    <div id="city-wrap"  class="slider">
        <label for="city">City & State</label>
        <input type="text" id="city" name="city" />
    </div><!--/#city-wrap-->

    <div id="zip-wrap"  class="slider">

        <label for="zip">Zip code</label>
        <input type="text" id="zip" name="zip" />
    </div><!--/#zip-wrap-->

    <input type="submit" id="btn" name="btn" value="submit" />
</form>

A simple form with DIVs wrapping labels and inputs. This probably looks like many of your forms.

Downloadify: Client-Side File Generation Using Javascript and Flash

Published by David Walsh on Tuesday, January 19, 201018 Comments

The following tools is in its very beta stages and works intermittently. Its so damn useful that I had to show it off now though!

I recently stumbled upon Downloadify, a client-side file generation tool based on javascript and Flash ActionScript code. A huge advantage to creating files on the client-side is that you can reduce the load on the server — especially when there’s no need for the server to get involved (the data is available within the page, etc.) Lets take a look at how we can use Downloadify.





© David Walsh 2007-2010. Contact David Walsh. Powered by the remarkable MooTools javascript framework.