Approximating resizeComplete in jQuery
Most browsers fire resize events continuously as the viewport is scaled. This is handy when your interface needs to change responsively during a resize, but a PITA if you only need to perform a single action when it’s “done.” Even worse is when that action is resource-intensive (such as an animation), as it can render your resize choppy or unbearable. I was faced with this very problem on a recent site design, and I thought I’d share the solution I arrived at.
The basic idea is to call a function within the resize() callback on a delay. This function checks to see if the width and height of the window have maintained dimensions during this period, and if so performs your resize completed action. Here is the code in jQuery:
- // global queue of setTimeout handles
- var handleQueue = new Array();
- $(window).resize(function() {
- // store current dimensions using .data()
- $(window).data(′oldW′, $(window).width()).data(′oldH′, $(window).height());
- // call our function on a delay and push its handle on the queue
- handleQueue.push(setTimeout(_completeCheck, 750));
- });
- function _completeCheck() {
- var $window = $(window);
- if ($window.width() == $window.data(′oldW′) && $window.height() == $window.data(′oldH′) {
- // *** DO YOUR RESIZE COMPLETE STUFF HERE ***
- // unwind setTimeout handle queue to prevent further execution
- while (handleQueue.length != 0)
- clearTimeout(handleQueue.shift());
- } else {
- // otherwise shift the first handle off since it already executed
- handleQueue.shift()
- }
- }
I chose to go the route of a handle queue because I feel it’s a lot cleaner than some global boolean. The boolean approach will still execute delayed function calls after the resize is “done,” and I’d rather unwind a queue and cancel those calls immediately since they’re unnecessary. You might also need to noodle with the setTimeout interval to achieve the responsiveness you’re after. In my case, 750ms was just right.
Potato Risotto
Last night I made and fell in love with potato “risotto,” a side dish found in this month’s Bon Appétit magazine. It requires a bit of knife work to get a uniform brunoise out of the potatoes, but the contrast of textures and flavor are both well worth the effort.
- 1 tbsp butter
- 1 cup finely diced onion
- 1 lb yukon gold potatoes brunoised
- 1/8 tsp cayenne pepper
- pinch of kosher salt
- 1 1/2-2 cups chicken stock
- 1/2 cup heavy cream
- 1/4 cup grated parmesan cheese
- 1/4 cup fresh chives
- Prepare potato brunoise—you have two options to begin: (1) cut the potato into a perfect rectangular box or (2) square off all sides and ends producing a rectangular box with rounded corners. The former is a lot more wasteful, but your brunoise will be perfectly uniform—go with whichever you prefer. To finish the brunoise cut the potato into 1/8” panels, rotate the stack 90° and cut into 1/8” juliennes, then cut the stacked juliennes into 1/8” cubes.
- Melt butter in a large sauce pan over medium heat. Add diced onions and sweat covered until translucent, stirring often.
- Add potatoes, 1.5 cups of stock, and cayenne pepper. Bring stock to a boil and reduce heat, simmering until potatoes are almost tender. Like a conventional risotto, add extra stock if needed and stir often. You’re looking for a creamy texture with a little bit of sauce in the pan.
- Add heavy cream and simmer until potatoes are tender but still hold their shape.
- Mix in parmesan cheese and chives before serving. Devour tout de suite.
If I could fault anything about this recipe it’d be that it’s a little on the rich side, so next time I’ll probably balance the fat with a little acid—either with white wine or lemon zest.
I too have thoughts on the iPad
I’ve given myself some time to mull over our latest gift from benevolent leader and arrived at this: bad name, exciting thesis, and nascent execution.
I’m happiest for Cassie, as come June she’ll have a shiny new iPad that fulfills her every need as a simple and inexpensive internet machine. I don’t feel like the iPad in its current form is compelling enough to steal me away from my Air, but its premise really excites me. Neven nails exactly why this is exciting, particularly from a UI/UX perspective:
And a bright light did shine upon my liberated face and a voice did whisper a thunder: You’re free. Free of pointless preferences and finger-baiting adjustments.
As Andy puts it, the iPad is an administrivia-removal device.
The iPad is to interface design what a magazine is to print design: a consistent, constrained, and explorable medium. That’s a refreshing break from designing UX around a multitude of permutations and preferences. Moreover, this freedom encourages you to re-imagine experiences from the ground up (as Apple has done with most of their core apps). Exciting times indeed.
Many people (most notably the Categorical Apple Denouncement Brigade™) are ready to call the iPad a flop due to missing bullet points, but I’m with Fraser Speirs: “What you’re seeing in the industry’s reaction to the iPad is nothing less than future shock.” The iPad’s positioning is decidedly forward, and in a culture trained to value malleability over elegance I can understand the backlash. It’ll be interesting to see how opinions maintain when people have the device in-hand.
I do have some beef with the interface—most notably the lock and home screens. The unimaginative use of space feels like an afterthought, and that strikes me as odd for something so prominent. I’m sure Apple will iterate this in future releases, but it’s clearly an area of deficiency in the current version. Also I’m not sold on the execution of the keyboard, which I imagine will be pretty clunky in portrait mode. I’ll wait until I play around with the it before I pass judgement, but I can’t picture it being very satisfying to use.
All in all the iPad is an intriguing first step into uncharted waters, and I can’t wait to check it out.
Kathleen Mallery on finding the best piano:
“What’s the best piano out there?” I asked.
The piano tuner’s eyes sparkled. ”I always get asked this question. Everyone always wants to know — what’s the best piano. And I always say, the piano that’s in your living room.”
”It’s all about getting it tuned right, bringing out its own sound and then when you play, you play the piano that’s in front you, and you see what it can really do. That’s all there is really. Tuning it and then playing what you’ve got.”I was fascinated to find, when I learned how to tune an old, not-so-special cello, that I could feel when it was in tune. Not just hear it, but feel it. A complete surprise to me, a former non-string player. When you slow down to tune, it resonates in a way that’s unmistakable.
I’ve played timpani most of my life, and one of my favorite things about the instrument is tuning by singing into it. You put your face close to the drumhead and hum your desired pitch, and when you depress the pedal to the right tension the entire kettle sympathetically resonates. In a split second you go from hearing only the sound of your hum to being completely enveloped by the pitch—almost like the drum is humming with you.
“When that chute opens you feel like you’ve done something kings and queens can’t even spell.”
— Gary Busey, on skydiving
“I think as a younger designer I was afraid if I did something that was cliched or literal straight out that that would ultimately be the end product, whereas now I look at it as sometimes you have to start there. Sometimes blue is blue and red is red and … as the process develops you start to question yourself and sort these things out as you go along.”
— Danny Yount