MooTools Kwicks Plugin

By on  
MooTools Kwicks

I wrote a post titled Get Slick with MooTools Kwicks ages ago. The post was quite popular and the effect has been used often. Looking back now, the original code doesn't look as clean as it could. I've revised the original Kwicks code so that Kwicks is laid out in the form of a standard MooTools plugin.


<div id="kwick">
	<ul id="kwicks">
		<li><a class="kwick john" href="http://en.wikipedia.org/wiki/John_lennon" title="John Lennon"><span>John Lennon</span></a></li>
		<li><a class="kwick paul" href="http://en.wikipedia.org/wiki/Paul_mccartney" title="Paul McCartney"><span>Paul McCartney</span></a></li>
		<li><a class="kwick george" href="http://en.wikipedia.org/wiki/George_harrison" title="George Harrison"><span>George Harrison</span></a></li>
		<li><a class="kwick ringo" href="http://en.wikipedia.org/wiki/Ringo_starr" title="Ringo Starr"><span>Ringo Starr</span></a></li>

The Kwicks system works based off of an HTML list containing list items with links.


#kwick						{ width:590px; }
	#kwicks 				{ height:143px; list-style-type:none; margin:0; padding:0; }
#kwick li 					{ float:left; }
#kwick .kwick 				{ display:block; cursor:pointer; overflow:hidden; height:143px; width:134px; }
#kwick .kwick span 			{ display:none; }

#kwick .john 				{ background:url(kwicks/john.gif) no-repeat; }
#kwick .paul 				{ background:url(kwicks/paul.gif) no-repeat; }
#kwick .george 				{ background:url(kwicks/george.gif) no-repeat; }
#kwick .ringo 				{ background:url(kwicks/ringo.gif) no-repeat; }

The most key of the selectors is ".kwick" which features "overflow:hidden". Overflow hidden will allow our squeezing of elements.

The MooTools JavaScript

var Kwicks = new Class({
	Implements: [Options],
	options: {
		squeezeWidth: 100,
		maxWidth: 285
	initialize: function(list,options) {
		this.list = document.id(list);
	parse: function() {
		var items = this.list.getElements('a'),
			fx = new Fx.Elements(items, {wait: false, duration: 250, transition:Fx.Transitions.Cubic.easeOut}),
			startWidths = [],
			options = this.options;
		//kwicks items
		items.each(function(item,i) {
				var fxSettings = {};
				fxSettings[i] = {
					'width': [item.getStyle('width').toInt(),options.maxWidth]
				items.each(function(sibling,ii) {
					if(sibling != item) {
						var w = sibling.getStyle('width').toInt();
						if (w != options.squeezeWidth) {
							fxSettings[ii] = {
								'width': [w,options.squeezeWidth] 
		this.list.addEvent('mouseleave',function() {
			var fxSettings = {};
			items.each(function(item,i) {
				fxSettings[i] = {
					width: [item.getStyle('width').toInt(), startWidths[i]]

/* USAGE */
window.addEvent('domready',function() {
	var kwicks = new Kwicks('kwicks');

Unlike my original post, this implementation works off of the MooTools Class system. The class is small and features only one real method but the class' code is also much cleaner than my original implementation!

The Kwicks effect is tasteful, smooth, and attention-grabbing. I recommend adding this to any website that could use a bit of dynamism.

O'Reilly Velocity Conference
Save 20% with discount code AFF20

Recent Features

Incredible Demos

  • Scroll IFRAMEs on iOS

    For the longest time, developers were frustrated by elements with overflow not being scrollable within the page of iOS Safari.  For my blog it was particularly frustrating because I display my demos in sandboxed IFRAMEs on top of the article itself, so as to not affect my site's...

  • Image Protection Using PHP, the GD Library, JavaScript, and XHTML

    Warning: The demo for this post may brick your browser. A while back I posted a MooTools plugin called dwProtector that aimed to make image theft more difficult -- NOT PREVENT IT COMPLETELY -- but make it more difficult for the rookie to average user...


  1. Amitay

    Very good…

    Where do you find the time to write all these plugins?

  2. Are you saying I have no life? :) Efficiency comes with practice.

  3. Awesome thanks for retooling it :)

  4. I really like Kwicks but the time it takes to make the images just perfect/right/etc has always deterred me from actually using it.

    Good work!

  5. Hmmmm….nice article david!! You are My teacher….

  6. Michael J Kormendy

    So how would we do this if we didn’t want to use a list?
    Lets say, a group of divs, within a div?

  7. Oh man, this is verrrry nice. I’ve been looking for something like this for quite a while and didn’t want to resort to flash.

    Also, kudos for using images of the fab four.

  8. Stefan

    Hi, I’m new to mootools.
    I need to use mootools version 1.2.1 for a project, so I created a mootools.js with all needed classes. But it doesn’t work.. It only works with your mootools.js, which I downloaded from your demo version. Is there an incompatibility? I tried also 1.2.4 and it doesn’t work, too. I hope you can help me!

  9. Hi mate! Love your Mootools magic :)

    However, I’ve discovered a weird bug in this class that seemingly only applies to Google Chrome. Sometimes, the startWidths doesn’t get properly filled, and the menu fold back to 0 pixels when your mouse leaves it. Haven’t been able to find a fix for this, unfortunately, I just hard-coded the values I needed into it.

  10. Samuel

    Hi David,

    I’ve been using SmoothScroll with Mootools core 1.3 (excellent plug-in, by the way) but can’t get Kwicks working with anything other than core 1.2.3. As I’d like to use both plug-ins on the same webpage, I was wondering if there’s anything you can suggest to fix it?

    Any help would be greatly appreciated, thanks.

    • Can you provide any detail as to the error?

    • Samuel

      The browser doesn’t give any errors when I try to use Kwicks with core 1.3; the images used just fail to expand upon mouseover.

      I’m probably just failing to implement the plug-in correctly. I managed to get it working using core 1.2.3 by following the example of your demo, and am assuming that to get it working with core 1.3 I just need to substitute one for the other and update which script the page loads.

      Out of curiosity, how would you go about changing your Kwicks demo so that it uses core 1.3?

      Thanks again, David.

  11. David

    I’ve just been updating a website from Moo 1.2 to 1.3, and with the compatibility layer active everything has gone smoothly, save for an odd bug with the Kwicks. It seems that mouseleave can fail to return the Kwicks to their initial size, if you hover over them too quickly. I’ve verified the problem with Safari and Firefox thus far.

    I’ve set up a js.fiddle to illustrate the problem:


    Any help on this would be much appreciated.

  12. David

    Fixed, there was a link:’cancel’ missing from the FX.Elements:


  13. David

    Fixed the flakey behaviour of mouse.leave in Moo 1.3, there was a link:’cancel’ missing from the FX.Elements:


  14. Really nice one and i would appreciate your thoughts.

  15. I be thankful for your thoughtful enter.

  16. Guys,

    I want to add social media buttons right after the blog post. How can I do that? Help!

    Thank you

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!

Recently on David Walsh Blog

  • Prevent Chrome from Translating a Page

    A while back I shared my favorite Google Chrome extension:  Google Art Project.  I've enjoyed seeing beautiful art when I open a new tab -- it's brought genuine happiness to my day, however small that happiness may be.  About a week ago, however, the art presented had...

  • Create Any Type Of Website With These Multi-Purpose Themes

    We have selected what we believe are the very best multipurpose WordPress themes on the market today. Our list contains a number of best sellers, several newcomers that are proving to be highly popular, and a few themes that are ideal for creating the types of...

  • An Introduction to Static Site Generators

    Static site generators seem to have been becoming more and more popular recently, but they’re not one of those ephemeral novelty things that grow in popularity as quickly as they fall into oblivion shortly after. For over a decade, many different projects — 394 of...

  • Automated Tests for Visual Responsive Layouts

    Today it's all about testing. In 2015, many developers knows about TDD and I personally think that testing is one of the key for quality products. But what about testing in a Front-end environment? How do you guys write your tests for a responsive page or...

  • Getting Dicey With Flexbox

    What if you could build complex CSS layouts in minutes? Flexbox is a new CSS layout spec that makes it easy to construct dynamic layouts. With flexbox, vertical centering, same-height columns, reordering, and direction agnosticism are a piece of cake. There's a popular myth floating around that...