Safari Firefox Chrome You are using Internet Explorer. Have you considered upgrading?
Mar 9th, 2010 by Barker Design
Create a Simple News Scroller Using Dojo

My journey into Dojo javascript has been exciting and I’m continuing to learn more as I port MooTools scripts to Dojo. My latest experiment is porting a simple new scroller from MooTools to Dojo. The code is very similar!

View Demo

The HTML

  • News Item 1Pellentesque habitant morbi...Read More
  • News Item 2Pellentesque habitant morbi...Read More

The news items are placed into list items. The UL will be the element that’s animated.

The CSS

#news-feed	 { height:200px; width:300px; overflow:hidden; position:relative; border:1px solid #ccc; background:#eee; }
#news-feed ul	{ position:absolute; top:0; left:0; list-style-type:none; padding:0; margin:0; }
#news-feed ul li { min-height:180px; font-size:12px; margin:0; padding:10px; overflow:hidden; }

The absolute positioning is essential to proper animation. Unlike my MooTools example, this example no longer requires a fixed height for each news item. I did add a minimum height so only one item shows up within the scroller window at a time.

The Dojo Javascript

dojo.require('dojo.NodeList-fx');
dojo.addOnLoad(function() {
	/* settings */
	var list = dojo.query('#news-feed ul'),
		items = list.query("li"),
		showDuration = 3000,
		scrollDuration = 500,
		scrollTopDuration = 200,
		index = 0,
		interval;

	/* movement */
	var start = function() { interval = setInterval(move,showDuration); };
	var stop = function() { if(interval) clearInterval(interval); };
	var reset = function() {
	    list.anim({ top: 0}, scrollTopDuration, null, start);
	};
	/* action! */
	var move = function() {
	    list.anim({ top: (0 - (dojo.coords(items[++index]).t)) }, scrollDuration, null, function(){
			if(index == items.length - 1) {
				index = 0-1;
				stop();
				setTimeout(reset,showDuration);
			}
	    });
	};

	/* stop and start during mouseenter, mouseleave  */
	list.onmouseenter(stop).onmouseleave(start);

	/* go! */
	start();
});

This is where I have the epic description…but the above code (at least for MooTools users) should look familiar. The logic is exactly the same but the code uses dojo.* methods instead of MooTools’ Fx, $$, $, and Element.Dimensions methods.

The MooTools Javascript

window.addEvent('domready',function() {
	/* settings */
	var list = $('news-feed').getFirst('ul');
	var items = list.getElements('li');
	var showDuration = 3000;
	var scrollDuration = 500;
	var index = 0;
	var height = items[0].getSize().y;
	/* action func */
	var move = function() {
		list.set('tween',{
			duration: scrollDuration,
			onComplete: function() {
				if(index == items.length - 1) {
					index = 0 - 1;
					list.scrollTo(0,0);
				}
			}
		}).tween('top',0 - (++index * height));
	};
	/* go! */
	window.addEvent('load',function() {
		move.periodical(showDuration);
	});
});

The above code was taken from my original post. Take a moment to compare the Dojo and MooTools code.

View Demo

What do you think? Three Dojo posts in — what are your thoughts about Dojo to this point?

Don’t forget to follow me on Twitter and be sure to visit Script & Style for the best Javascript and CSS articles around!Sponsor the David Walsh Blog and get your brand in front of several thousand users per day!

Create a Simple News Scroller Using Dojo

Related posts:

  1. Create a Simple News Scroller Using MooTools, Part I: The Basics
  2. Link Nudging Using Dojo
  3. Remove Broken Images Using Dojo
  4. QuickBoxes for Dojo
  5. Using MooTools 1.2 For Drag, Drop, Sort, Save

 
Mar 8th, 2010 by Barker Design
“MooTools as a General Purpose Application Framework” by Christoph Pojer

I wanted to bring attention to an outstanding presentation given by MooTools Core Developer Christoph Pojer.  Given at FOSDEM 2010, Christoph provides an overview of what MooTools is, who should use it, how it should be used.  Examples are given throughout the presentation. 

I highly recommend MooTools users of all experience levels watch this video, as well as jQuery or Dojo users looking to simply understand what this framework is about.

Don’t forget to follow me on Twitter and be sure to visit Script & Style for the best Javascript and CSS articles around!Sponsor the David Walsh Blog and get your brand in front of several thousand users per day!

“MooTools as a General Purpose Application Framework” by Christoph Pojer

Related posts:

  1. Following MooTools on Twitter
  2. When Javascript Frameworks Collide
  3. What Would You Like From Your Framework?
  4. 5 Ways to Contribute to Your Favorite Javascript Framework
  5. Book Review: PHP5 CMS Framework Development

 
Mar 2nd, 2010 by Barker Design
Remove Broken Images Using Dojo

In an effort to get better with the Dojo Toolkit, I’ve decided to port yet another one of my previous posts: Remove Broken Images Using MooTools or jQuery. Broken images are an eyesore to any website so there’s no point to keeping them in the page. Here’s how you can remove them on the client side.

The Dojo Javascript

dojo.ready(function() {
	dojo.query('img').forEach(function(img){
		dojo.connect(img,'onerror',function() {
			dojo.destroy(img);
		});
	});
});

Just as simple as jQuery and MooTools — just a different syntax!

Don’t forget to follow me on Twitter and be sure to visit Script & Style for the best Javascript and CSS articles around!Sponsor the David Walsh Blog and get your brand in front of several thousand users per day!

Remove Broken Images Using Dojo

Related posts:

  1. Remove Broken Images Using MooTools or jQuery
  2. Link Nudging Using Dojo
  3. QuickBoxes for Dojo
  4. Send Email Notifications for Broken Images Using MooTools Ajax
  5. Send Email Notifications for Broken Images Using jQuery Ajax

 
Mar 1st, 2010 by Barker Design
Link Nudging Using Dojo

Dojo Toolkit

In the past we’ve tinkered with link nudging with MooTools and link nudging with jQuery. In an effort to familiarize myself with other javascript frameworks, we’re going to try to duplicate that effect with another awesome framework: Dojo.

View Demo

The Javascript: Attempt 1

dojo.addOnLoad(function() {
	var links = dojo.query('a.nudge');
	//foreach...
	dojo.forEach(links,function(link) {
		var left = dojo.style(link,'paddingLeft');
		dojo.connect(link,'onmouseenter',function() {
			dojo.animateProperty({
				node:link,
				properties: {
					paddingLeft: 20
				}
			}).play();
		});
		dojo.connect(link,'onmouseleave',function() {
			dojo.animateProperty({
				node:link,
				properties: {
					paddingLeft: left
				}
			}).play();
		});
	});
});

Once the DOM is ready, we use the dojo.query method to find all of the links to nudge. For every link we find, we record its original left padding and add mouseenter and mouseleave events to each link to animate its left padding.

The Javascript: Better Solution

dojo.ready(function() {
	dojo.query('a.nudge').forEach(function(link){
		var left = dojo.style(link,'paddingLeft');
		dojo.connect(link,'onmouseenter',function() {
		    dojo.anim(link, { paddingLeft:20 });
		});
		dojo.connect(link,'onmouseleave',function() {
		    dojo.anim(link, { paddingLeft:left });
		});
	});
});

Dojo lead Pete Higgins showed me a more condensed version of his script.

View Demo

Simple, no? The best way to learn to use any javascript framework is to duplicate a given set of code you are familiar with, much like we did here. What do you think about this Dojo example? Look close to jQuery and MooTools?

Don’t forget to follow me on Twitter and be sure to visit Script & Style for the best Javascript and CSS articles around!Sponsor the David Walsh Blog and get your brand in front of several thousand users per day!

Link Nudging Using Dojo

Related posts:

  1. jQuery Link Nudging
  2. QuickBoxes for Dojo
  3. MooTools Link Nudging
  4. jQuery Link Nudge Plugin
  5. jQuery Random Link Color Animations

 
Feb 26th, 2010 by Barker Design
jQuery Podcast & Essential jQuery and MooTools Snippets

jQuery

Many of you probably already know this but I like to consider myself a bit of a javascript chameleon. If you know that then you probably know I’m a MooTools fanatic that periodically dabbles with jQuery. I’m happy to announce that I was able to join Elijah Manor and Ralph Whitbeck on the jQuery podcast this past week to talk jQuery, MooTools, and web development in general. Head on over to the jQuery blog for more information or iTunes to grab the podcast.

As an extension of my podcast appearance, I wanted to share a few code snippets to make your introduction to MooTools or jQuery easier.

Featured jQuery & MooTools Snippets

Using jQuery and MooTools Together

Did you know that you can use jQuery and MooTools within the same page? It’s easy to!

<script type="text/javascript" src="moo1.2.4.js"></script>
<script type="text/javascript" src="jquery-1.4.js"></script>
<script type="text/javascript">
window.addEvent('domready',function() { //moo stuff
	$('p').css('border','1px solid #fc0'); //jquery
});
</script>

Using Sizzle Within MooTools

Prefer to use jQuery’s selector engine within MooTools? No problem — here’s how:

//just as reader "Ryan" mentioned....
Window.$$ = function(selector){
	return new Elements(new Sizzle(selector));
}

jQuery and MooTools Link Nudging

Link nudging is a classy, subtle effect that makes your websites more dynamic.

/* jquery */
$.fn.nudge = function(params) {
	//set default parameters
	params = $.extend({
		amount: 20,
		duration: 300,
		property: 'padding',
		direction: 'left',
		toCallback: function() {},
		fromCallback: function() {}
	}, params);
	//For every element meant to nudge...
	this.each(function() {
		//variables
		var $t = $(this);
		var $p = params;
		var dir = $p.direction;
		var prop = $p.property + dir.substring(0,1).toUpperCase() + dir.substring(1,dir.length);
		var initialValue = $t.css(prop);
		/* fx */
		var go = {}; go[prop] = parseInt($p.amount) + parseInt(initialValue);
		var bk = {}; bk[prop] = initialValue;

		//Proceed to nudge on hover
		$t.hover(function() {
					$t.stop().animate(go, $p.duration, '', $p.toCallback);
				}, function() {
					$t.stop().animate(bk, $p.duration, '', $p.fromCallback);
				});
	});
	return this;
};

/* jquery usages */
$(document).ready(function() {
	/* usage 1 */
	$('#nudgeUs li a').nudge();
	/* usage 2 */
	$('#nudgeUs2 li a').nudge({
		property: 'margin',
		direction: 'left',
		amount: 30,
		duration: 400,
		toCallback: function() { $(this).css('color','#f00'); },
		fromCallback: function() { $(this).css('color','#000'); }
	});
});

/* mootols link nudge */
window.addEvent('domready',function() {
	$$('#nudges a').addEvents({
		'mouseenter': function() { this.tween('padding-left',20); },
		'mouseleave': function() { this.tween('padding-left',0); }
	});
});
View jQuery Demo View jQuery Demo

jQuery and MooTools Search Bookmarklets

These bookmarklets will allow you to highlight text on a page and search the jQuery or MooTools websites to learn more about the phrase.

jQuery BookmarkletMooTools Bookmarklet

 

jQuery Events within MooTools

The following MooTools snippet allows you to use jQuery-style syntax for event listening.

//hash the element.natives so we can do stuff with it
var hash = new Hash(Element.NativeEvents);
//remove items that need to be replaced, add their replacements
hash.erase('mouseover').erase('mouseout').erase('DOMMouseScroll');
hash.include('mouseenter',1).include('mouseleave',1);
//initialize this
var eventHash = new Hash({});
//for every event type, add to our hash
hash.getKeys().each(function(event){
	eventHash[event] = function(fn) {
		this.addEvent(event,fn);
		return this;
	}
});
//make it happen
Element.implement(eventHash);

 

JavaScript FTW!

Here are a few other MooTools and jQuery tutorials you may like:

Isn’t the javascript community great? MooTools FTW!

Don’t forget to follow me on Twitter and be sure to visit Script & Style for the best Javascript and CSS articles around!Sponsor the David Walsh Blog and get your brand in front of several thousand users per day!

jQuery Podcast & Essential jQuery and MooTools Snippets

Related posts:

  1. jQuery Link Nudge Plugin
  2. Implementing jQuery-Like Event Syntax in MooTools
  3. Using jQuery and MooTools Together
  4. Count MooTools Events Per Element in MooTools 1.2
  5. Implement MooTools’ Elements.addEvent in jQuery

 
Feb 25th, 2010 by Barker Design
Fixing Python’s “Python Eggs” Error

Let me first state this for the record: I am not a server guy. The closest I’ve ever gotten to compiling my own versions of code is “sudo port install …” So when I decided to teach myself Python (creating simply database interaction, record listings, etc) and kept getting “500 Internal Server Error” messages, I thought I was doomed. I opened up the Apache error log and saw this:

[error] [client ::1] Traceback (most recent call last):
[error] [client ::1]   File "/Users/davidwalsh83/Projects/server/something.py", line 6, in <module>
[error] [client ::1]     import MySQLdb, cgi, cgitb, httplib, urllib2
[error] [client ::1]   File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in <module>
[error] [client ::1]   File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in <module>
[error] [client ::1]   File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 4, in __bootstrap__
[error] [client ::1]   File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 835, in resource_filename
[error] [client ::1]     self, resource_name
[error] [client ::1]   File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 1304, in get_resource_filename
[error] [client ::1]     self._extract_resource(manager, self._eager_to_zip(name))
[error] [client ::1]   File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 1326, in _extract_resource
[error] [client ::1]     self.egg_name, self._parts(zip_path)
[error] [client ::1]   File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 915, in get_cache_path
[error] [client ::1]     self.extraction_error()
[error] [client ::1]   File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 881, in extraction_error
[error] [client ::1]     raise err
[error] [client ::1] pkg_resources.ExtractionError: Can't extract file(s) to egg cache
[error] [client ::1]
[error] [client ::1] The following error occurred while trying to extract file(s) to the Python egg
[error] [client ::1] cache:
[error] [client ::1]
[error] [client ::1]   [Errno 20] Not a directory: '/Library/WebServer/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp'
[error] [client ::1]
[error] [client ::1] The Python egg cache directory is currently set to:
[error] [client ::1]
[error] [client ::1]   /Library/WebServer/.python-eggs
[error] [client ::1]
[error] [client ::1] Perhaps your account does not have write access to this directory?  You can
[error] [client ::1] change the cache directory by setting the PYTHON_EGG_CACHE environment
[error] [client ::1] variable to point to an accessible directory.
[error] [client ::1]
[error] [client ::1] Premature end of script headers: something.py

My first thought was “Wow, that’s quite a long way of telling me to ‘just quit.’” Not wanting to concede defeat, I did some quick Google searching to find that the following snippet of Python code would allow me program another day:

import os
os.environ['PYTHON_EGG_CACHE'] = '/tmp'

I’d like to pretend I know what that means but I really don’t know. In any event, if you start receiving those errors, this snippet could be your ticket to taking a bite out of Python.

Don’t forget to follow me on Twitter and be sure to visit Script & Style for the best Javascript and CSS articles around!Sponsor the David Walsh Blog and get your brand in front of several thousand users per day!

Fixing Python’s “Python Eggs” Error

Related posts:

  1. Custom Error Handling in PHP
  2. Custom Error Page Tips – Designate The Pages You Hope No One Sees
  3. PHP, ODBC, and nvarchar
  4. google.load(): Utilize Google’s Ajax Libraries API
  5. Prevent Directory Listings With .htaccess

 
Feb 23rd, 2010 by Barker Design
Create a Simple News Scroller Using MooTools, Part I: The Basics

News Scroller

News scroller have been around forever on the internet. Why? Because they’re usually classy and effective. Over the next few weeks, we’ll be taking a simple scroller and making it into a flexible, portable class. We have to crawl before we walk though; let’s make a simple news scroller using MooTools.

View Demo

The HTML

<div id="news-feed">
	<ul>
		<li><strong style="font-size:14px;">News Item 1</strong><br />Pellentesque habitant morbi...<a href="#">Read More</a></li>
		<li><strong style="font-size:14px;">News Item 2</strong><br />Pellentesque habitant morbi...<a href="/news/2">Read More</a></li>
		<!-- more.... -->
	</ul>
</div>

The HTML part is fairly simple: a list with numerous list items (news items) wrapped in a single DIV.

The CSS

#news-feed	 { height:200px; width:300px; overflow:hidden; position:relative; border:1px solid #ccc; background:#eee; }
#news-feed ul	{ position:absolute; top:0; left:0; list-style-type:none; padding:0; margin:0; }
#news-feed ul li { height:180px; font-size:12px; margin:0; padding:10px; overflow:hidden; }

Getting the CSS correct is very important for our simple scroller. The wrapper DIV must be positioned relative and the UL must be positioned absolutely. Each LI’s height + padding/margin/border must be the same height as the UL itself.

The MooTools Javascript

window.addEvent('domready',function() {
	/* settings */
	var list = $('news-feed').getFirst('ul');
	var items = list.getElements('li');
	var showDuration = 3000;
	var scrollDuration = 500;
	var index = 0;
	var height = items[0].getSize().y;
	/* action func */
	var move = function() {
		list.set('tween',{
			duration: scrollDuration,
			onComplete: function() {
				if(index == items.length - 1) {
					index = 0 - 1;
					list.scrollTo(0,0);
				}
			}
		}).tween('top',0 - (++index * height));
	};
	/* go! */
	window.addEvent('load',function() {
		move.periodical(showDuration);
	});
});

The settings will be placed at the top of the code block, as always. Once the settings are defined, a function is created that scrolls from the current news item to the next news item. Once the scroller reaches the last news item, it scrolls back to the first one. Lastly, when the page has loaded, the directive to start the news scroller is given.

View Demo

Creating a basic scroller is super simple. Look forward to future posts expanding the capabilities of our scroller, including creating a class and adding events.

Don’t forget to follow me on Twitter and be sure to visit Script & Style for the best Javascript and CSS articles around!Sponsor the David Walsh Blog and get your brand in front of several thousand users per day!

Create a Simple News Scroller Using MooTools, Part I: The Basics

Related posts:

  1. MooTools Font-Size Scroller with Cookie Save
  2. Create a Simple Slideshow Using MooTools
  3. Create a Simple Slideshow Using MooTools, Part II: Controls and Events
  4. Create a Simple Slideshow Using MooTools, Part IV: Thumbnails and Captions
  5. Using MooTools 1.2 For Drag, Drop, Sort, Save

 
Feb 22nd, 2010 by Barker Design
Create a Simple Slideshow Using MooTools, Part IV: Thumbnails and Captions

MooTools Slideshow

My “Create a Simple Slideshow Using MooTools” series has been hugely successful. The first step was laying the groundwork for the slideshow, the second step was adding controls and events to the slideshow, and the third step was recoding the slideshow into a sexy class. This fourth slideshow tutorial will add thumbnail previews and captions to the slideshow.

View Demo

No Class? WTF!?

I’ve chosen to revert back to the “inline” code from the second tutorial. Why? I’m going a little bit off of the reservation with this one. I think classes are important to use when you want a more generic slideshow; this one will be a bit more customized. That isn’t to say, however, that I wont be creating another class in the future.

The HTML

Christina Ricci 1::This is the caption for photo 1. Christina Ricci 2::This is the caption for photo 2. Christina Ricci 3::This is the caption for photo 3. Christina Ricci 4::This is the caption for photo 4. Christina Ricci 5::This is the caption for photo 5.

Isn’t it nice that our base HTML code hasn’t changed since the first tutorial? :)

The CSS

#slideshow-container	{ width:512px; height:384px; position:relative; }
#slideshow-container img { width:512px; height:384px; display:block; position:absolute; top:0; left:0; z-index:1; }
#slideshow-container-controls { margin:10px 0 0 0; }
	#slideshow-container-controls img { cursor:pointer; width:100px; height:75px; border:1px solid #ccc; float:left; margin:0 1px 0 0; }
#slideshow-container-caption  { height:70px; position:absolute; bottom:0; left:0; right:0; background:#000; z-index:10; overflow:hidden; }
	* html #slideshow-container-caption { width:100%; }
	#slideshow-container-caption h3 { font-size:24px; font-weight:bold; color:#fff; padding:10px 10px 3px 10px; }
	#slideshow-container-caption p	{ color:#eee; font-size:11px; padding:0 10px 10px 10px; }
.toc-active				{ border-color:#000; }

We’ve added a bit of CSS for the forthcoming controls/thumbnails and the caption elements. The caption will have a black background with light text. The thumbnails will be very small, floated next to each other, with fixed dimensions.

The MooTools Javascript

window.addEvent('domready',function() {
	/* settings */
	var showDuration = 5000;
	var container = $('slideshow-container');
	var images = container.getElements('img');
	var currentIndex = 0;
	var interval;
	var toc = [];
	var tocActive = 'toc-active';
	var thumbOpacity = 0.7;

	/* new: create caption area */
	var captionDIV = new Element('div',{
		id: 'slideshow-container-caption',
		styles: {
			//display:none,
			opacity: thumbOpacity
		}
	}).inject(container);
	var captionHeight = captionDIV.getSize().y;
	captionDIV.setStyle('height',0);

	/* new: starts the show */
	var start = function() { interval = show.periodical(showDuration); };
	var stop = function() { $clear(interval); };
	/* worker */
	var show = function(to) {
		images[currentIndex].fade('out');
		toc[currentIndex].removeClass(tocActive).fade(thumbOpacity);
		images[currentIndex = ($defined(to) ? to : (currentIndex < images.length - 1 ? currentIndex+1 : 0))].fade('in');
		toc[currentIndex].addClass(tocActive).fade(1);
		captionDIV.set('tween',{
			onComplete: function() {
				captionDIV.set('tween',{
					onComplete: $empty
				}).tween('height',captionHeight);
				/* parse caption */
				var title = '';
				var captionText = '';
				if(images[currentIndex].get('alt')) {
					cap = images[currentIndex].get('alt').split('::');
					title = cap[0];
					captionText = cap[1];
					captionDIV.set('html','

' + title + '

' + (captionText ? ' ' + captionText + ' ' : '')); } } }).tween('height',0); }; /* new: create preview area */ var preview = new Element('div',{ id: 'slideshow-container-controls' }).inject(container,'after'); /* new: control: table of contents */ images.each(function(img,i){ /* add to table of contents */ toc.push(new Element('img',{ src: img.get('src'), title: img.get('alt'), styles: { opacity: thumbOpacity }, events: { click: function(e) { if(e) e.stop(); stop(); show(i); start(); }, mouseenter: function() { this.fade(1); }, mouseleave: function() { if(!this.hasClass(tocActive)) this.fade(thumbOpacity); } } }).inject(preview)); if(i > 0) { img.set('opacity',0); } }); /* control: start/stop on mouseover/mouseout */ container.addEvents({ mouseenter: function() { stop(); }, mouseleave: function() { start(); } }); /* start once the page is finished loading */ window.addEvent('load',function(){ show(0); start(); }); });

The first step is creating the caption container within the main image container. We measure the height of the caption container and hide it right away to prevent it from being seen. The next step is adding a few chained tweens within the show method that parses the image’s alt attribute, sets the HTML within the caption container, and slides it up and down. I set the HTML of the caption container instead of using MooTools to create new H3 and P elements because (a) setting the HTML is faster and (b) we have no plan to do anything with each element individually.

A preview container is also created to hold the thumbnails. As we cycle through the large images, we create IMG elements with a fixed size (from the CSS above) that will act as thumbnail navigation for the slideshow. As an image receives focus, it’s border and opacity changes to show focus. Awesome!

View Demo

Do you like this version better than the previous? I certainly do. Look forward to a class version soon. Have any improvement ideas? Share them!

Download PDF

Don’t forget to follow me on Twitter and be sure to visit Script & Style for the best Javascript and CSS articles around!Sponsor the David Walsh Blog and get your brand in front of several thousand users per day!

Create a Simple Slideshow Using MooTools, Part IV: Thumbnails and Captions

Related posts:

  1. Create a Simple Slideshow Using MooTools
  2. Create a Simple Slideshow Using MooTools, Part III: Creating a Class
  3. Create a Simple Slideshow Using MooTools, Part II: Controls and Events
  4. 5 Simple Ways Programmers and Designers Should Give Back
  5. David Walsh on NetTuts: Create a Twitter-Like “Load More” Widget

 
Feb 17th, 2010 by Barker Design
NetTuts: Make Your MooTools Code Shorter, Faster, and Stronger

MooTools Faster

My latest NetTuts tutorial has hit! From the post:

MooTools is one of the most flexible, modular, and well written JavaScript frameworks available. So many people use it but many of them don’t optimize their code. This post will provide you with fifteen simple tips for making your MooTools code shorter, faster, and stronger.

Don’t miss it! http://net.tutsplus.com/tutorials/javascript-ajax/make-your-mootools-code-shorter-faster-and-stronger/

Download PDF

Don’t forget to follow me on Twitter and be sure to visit Script & Style for the best Javascript and CSS articles around!Sponsor the David Walsh Blog and get your brand in front of several thousand users per day!

NetTuts: Make Your MooTools Code Shorter, Faster, and Stronger

Related posts:

  1. NetTuts: Sexy Animated Tabs Using MooTools
  2. David Walsh on NetTuts: Create a Twitter-Like “Load More” Widget
  3. NetTuts Exclusive: Twitter Emulation Using MooTools 1.2 and PHP
  4. Using MooTools ScrollSpy to Load More Items via JSON/AJAX
  5. PHP Optimization – Using A Timer To Benchmark Code And Increase Speed

 
Feb 16th, 2010 by Barker Design
Background Animations Using MooTools

MooTools background animation

One of the sweet effects made easy by javascript frameworks like MooTools and jQuery is animation. I ran across this great jQuery tutorial that walks you through animating a background image of a page. Here’s a quick MooTools code snippet that shows you how you can add this sweet effect to any element on a page.

View Demo

The CSS

#animate-area	{ background:url(bg-clouds.png) 0 0 repeat-x; }

The first step is assigning the image as a background image for our given container. Be sure to repeat the background horizontally!

The MooTools Javascript

window.addEvent('domready',function() {
	//settings
	var duration = 5000;
	var length = 2000;
	var count = 0;
	var tweener = $('animate-area').set('tween',{ duration: duration, transition: 'linear' });
	//showtime!
	var run = function() {
		tweener.tween('background-position','-' + (++count * length) + 'px 0px');
	};
	run();
	run.periodical(duration);
});

The first step, as always is getting our settings ready for the show. The next piece is putting the animation function in place. We increment the negative background left position counter calculation to keep the show rolling. Last step is playing the show!

View Demo

Make sure the animation speed is very slow and subtle — a rapid background speed could make your users pass out. On the other hand, implementing it tastefully will make your website unique.

Download PDF

Don’t forget to follow me on Twitter and be sure to visit Script & Style for the best Javascript and CSS articles around!Sponsor the David Walsh Blog and get your brand in front of several thousand users per day!

Background Animations Using MooTools

Related posts:

  1. Create Snook-Style Navigation Using MooTools
  2. CSS Fixed Position Background Image
  3. Introducing MooTools ScrollSidebar
  4. MooTools, Mario, and Portal
  5. Sexy Opacity Animation with MooTools or jQuery

 

Authors

» Substance: WordPress » Style: Audacity of Tanish