One of my favorite bits of code I’ve ever done is on the front page of my jiggy, ancient, perpetually-under-construction, virtually-never-viewed old personal website, Life In A Mikeycosm. Eager to make my front page “pop” a little more back in days gone by, I came up with a clever CSS3/javascript hack that caused the page text and logo to slip and slide in three dimensions in response to your mouse movements, rendering the page somewhere between difficult and totally unusable for actually navigating the content of the site. I’ve always been inordinately fond of this.
I’ve embedded it below so you can experience the source of my amusement. Actually, if you click through the above link to the real site, at the bottom left there’s a “Stop this crazy thing” link that stops the animation and moves the links into rows so they’re readable and clickable. I don’t know if the below embed is big enough to show this, though. When animated, the moving links are indeed clickable, if you can catch one with your mouse to click on it. I added a glow-on-hover text effect to indicate when the mouse is over a link and it’s clickable.
Really, I find the whole thing pretty entertaining.
An explanation of how it’s done is below. There’s a “stop this crazy” thing link in the lower left, but depending on your screen dimensions it might be cut off, you might need to stretch the embedded view by dragging the little resize nubbin at the bottom right corner to see the whole kit & kaboodle (Note to web developers: yes, it’s a resizable iframe. Eat that!)
How It’s Done:
The html layout of the page is extremely simple. It’s a couple of section headings, followed by links, laid out in a pretty simply, like this:
{!{code}!}czozNTI6XCImbHQ7bnhiciZndDsmbHQ7YiZndDtTZWN0aW9uIDE6Jmx0Oy9iJmd0OyZhbXA7bmJzcDsgJmFtcDtuYnNwOw0KJmx0O2F7WyYqJl19IGhyZWY9XCJpbm5lcnBhZ2UxLmh0bWxcIiZndDtQYWdlIDEgdGl0bGUmbHQ7L2EmZ3Q7DQombHQ7L254YnImZ3Q7DQomYW1wO25ic3A7e1smKiZdfSAmYW1wO25ic3A7Jmx0O3diciZndDsNCiZsdDtueGJyJmd0OyZsdDthIGhyZWY9XCJpbm5lcnBhZ2UyLmh0bWxcIiZndDtQYWdlIDImbHtbJiomXX10Oy9hJmd0OyZsdDsvbnhiciZndDsNCiZhbXA7bmJzcDsgJmFtcDtuYnNwOyZsdDt3YnImZ3Q7DQombHQ7bnhiciZndDsmbHQ7YSBoe1smKiZdfXJlZj1cImlubmVycGFnZTMuaHRtbFwiJmd0O1BhZ2UgMyZsdDsvYSZndDsmbHQ7L254YnImZ3Q7IFwiO3tbJiomXX0={!{/code}!}
The only thing that bears some explanation is those custom <nxbr> tags. The reason for those is, this site actually dates back to the very earliest days of my web development, back in the mid ’90s. For a while, before I made the page dynamic and jiggery, I just wanted to control the wrapping so titles didn’t break across lines, and those started life as
<nobr>
tags. Over time <nobr>
tags came to be deprecated, and I’m sure as I was trying to animate things there were some conflicts, or something—this was all decades ago now—and I wound up using CSS to format things how I wanted, but left the tags in, converted to absolutely meaningless <nxbr>
tags, because in my neophyte days I guess I wasn’t yet aware you could do <div class="...">
or <span class="...">
or something. Anyway, at this point, all <nxbr>…</nxbr> is doing is marking the individual links, because I want to animate them separately.Then, the magic starts with this CSS:
{!{code}!}czoxMDU1OlwiDQoNCm54YnIgew0KCWRpc3BsYXk6IGlubGluZS1ibG9jazsNCn07DQoNCmJvZHkgew0KCXBvc2l0aW9uOiBhYnNvbHV7WyYqJl19dGU7DQoJcGVyc3BlY3RpdmU6IDMwMHB4Ow0KCXdpZHRoOiAxMDAlOw0KCWhlaWdodDogMTAwJTsNCglvdmVyZmxvdzogaGlkZGVuO3tbJiomXX0NCn0NCg0KbnhiciB7DQoJZGlzcGxheTogaW5saW5lLWJsb2NrOw0KCS13ZWJraXQtdHJhbnNpdGlvbjogYWxsIDEwMDBtczsNCgkte1smKiZdfW1vei10cmFuc2l0aW9uOiBhbGwgMTAwMG1zOw0KCS1vLXRyYW5zaXRpb246IGFsbCAxMDAwbXM7DQoJdHJhbnNpdGlvbjogYWxsIDF7WyYqJl19MDAwbXM7DQoJbWFyZ2luLXRvcDogLjVlbTsNCgltYXJnaW4tYm90dG9tOiAuNWVtOw0KfQ0KDQpueGJyOm50aC1vZi10eXBlKDNuKXtbJiomXX0geyAvL2V2ZXJ5IHRoaXJkIG54YnINCgl0cmFuc2Zvcm06IHJvdGF0ZVgoLTVkZWcpIHJvdGF0ZXkoLTEwZGVnKSB0cmFuc2xhdGV6e1smKiZdfSg0NXB4KTsNCn0NCg0KbnhicjpudGgtb2YtdHlwZSgzbisxKSB7IC8vb25lIGFmdGVyIGV2ZXJ5IHRoaXJkIG54YnINCgl0cmFuc2Z7WyYqJl19b3JtOiByb3RhdGVYKDBkZWcpIHRyYW5zbGF0ZXooNTBweCk7DQp9DQoNCm54YnI6bnRoLW9mLXR5cGUoM24rMikgeyAvL3NlY29uZHtbJiomXX0gYWZ0ZXIgZXZlcnkgdGhpcmQgbnhicg0KCXRyYW5zZm9ybTogcm90YXRlWCg1ZGVnKSByb3RhdGV5KDEwZGVnKSB0cmFuc2xhdGV6e1smKiZdfSg1NXB4KTsNCn0NCg0KI21rVGl0bGUgew0KCS8vIHRoaXMgaXMgdGhlIGJhY2tncm91bmQgaW1hZ2UgZGlzcGxheTogYmxvY2s7DQp7WyYqJl19CXBvc2l0aW9uOiBhYnNvbHV0ZTsNCglvcGFjaXR5OiAuMjsNCgltYXJnaW46IDEwMHB4IDE1cHg7DQoJcG9pbnRlci1ldmVudHM6IHtbJiomXX1ub25lOw0KCXdpZHRoOiA5MCU7DQoJaGVpZ2h0OiA5MCU7DQoJLy9zZXQgdGhlIGltYWdlIHRvIG1vdmUgbmljZSAmYW1wOyBzbG93e1smKiZdfWx5IA0KCS13ZWJraXQtdHJhbnNpdGlvbjogYWxsIDExNTAwbXM7DQoJLW1vei10cmFuc2l0aW9uOiBhbGwgMTE1MDBtczsNCgktby17WyYqJl19dHJhbnNpdGlvbjogYWxsIDExNTAwbXM7DQoJdHJhbnNpdGlvbjogYWxsIDExNTAwbXM7DQoJei1pbmRleDogLTEwMDAwOw0KfQ0KXCJ7WyYqJl19O3tbJiomXX0={!{/code}!}
Those nxbr:nth-of-type(3n) rules create three different alternating sets of tags, defined individually by those <nxbr> tags.
Then, having already loaded jQuery, this script tells the four CSS rules how to animate the <nxbr> tags to which they apply:
{!{code}!}czoyNzQ2OlwiDQoNCi8vJmx0OyFbQ0RBVEFbDQokKGRvY3VtZW50KS5yZWFkeShmdW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lIGluIGVhY2ggZGVjbGFyYXRpb257WyYqJl19IGJlY2F1c2UgaW4gRmlyZWZveCBpdCBkb2VzblwndCBpbmhlcml0IGRvd24gcGFzdCBpbW1lZGlhdGUgY2hpbGRyZW4gb2YgZWxlbWV7WyYqJl19bnQgaXRcJ3MgYXBwbGllZCB0bw0KICAgICAgICAgICAgfSk7DQoNCiAgICAgICAgICAgICQoXCJueGJyOm50aC1vZi10eXBlKDRuKzMpe1smKiZdfTpub3QoXCcubm9ybWFsXCcpXCIpLmNzcyh7IC8vY29sb3I6XCdwdXJwbGVcJywNCiAgICAgICAgICAgICAgICBcJ3RyYW5zZm9ybVwnOiBcJ3BlcntbJiomXX1zcGVjdGl2ZSgzMDBweCkgcm90YXRlWChcJyArICg3ICogKFhwb3MgLyA1MCkgLyAxMDApICsgXCdkZWcpIHJvdGF0ZXkoXCcgKyAoMzYwe1smKiZdfSArIC0xNSAqIChNYXRoLnRhbihZcG9zKSAqIDEwMCAtIDUwKSAvIDEwMCkgKyBcJ2RlZykgdHJhbnNsYXRleihcJyArICgyNSAqIChYcHtbJiomXX1vcyAvIChZcG9zICsgMjAwKSArIC41KSkgKyBcJ3B4KVwnDQogICAgICAgICAgICB9KTsNCg0KICAgICAgICB9KTsNCg0KICAgIH0NCn17WyYqJl19KTsNCg0KLy9dXSZndDsNCg0KXCI7e1smKiZdfQ=={!{/code}!}
That’s about it. There’s plenty of cruft in there, and if you look at the page code it’s even messier… it includes javascript libraries it doesn’t need, etc. It’s pretty obvious I was still figuring all this out back then. But, hey, it works! Just ask anyone who’s tried to click one of the links to access one of the internal pages, if anyone ever had.
There was just a little bit more CSS and jQuery, to get the “stop” button working, which I’ll add here at a later date.