December 20, 2013

jQuery: Combining Effects to Make Your Site Sizzle

jQuery, the popular framework for short-handing complex actions in JavaScript, has been extended by many developers around the world to do create some pretty slick in-browser effects. Today, let’s combine a couple of those together (along with some CSS effects) and make your page content a little more interesting.

Effect Number 1: Hover Blur

Mary Lou (Manoela Ilic) created a nice tutorial on making some items come into focus (while the others blur) as you mouse over them. Simple, and smart implementation.

Effect Number 1: Waypoints – initiate an action when something comes into view

Waypoints is an excellent jQuery extension built by Caleb (who is here in Portland, Oregon) which allows you to trigger events when something is brought into the browser. It couldn’t be easier to implement.

What do we want to achieve?

I simply want a box of text to be “highlighted” (in this case, to focus/enlarge while others on the page blur/shrink).

Jquery Combining Effects

Thanks to the ease-of-use of these other pieces of code, this shouldn’t be too difficult of a task.

Here is our code in jsfiddle

In our case, we want to keep Mary Lou’s functionality fully in-tact (when I put my mouse over a callout box, bring it to focus), but we also want to add the triggered event to automatically happen when the page is scrolled to the level of the callout box – this is where waypoints come in.

[code]

$articles.waypoint(function (direction) { var $article = $(this); clearTimeout(timeout); timeout = setTimeout(function () { if ($article.hasClass(‘active’)) { return false; } $articles.not($article.removeClass(‘blur’).addClass(‘active’)).removeClass(‘active’).addClass(‘blur’); }, 65); }, { offset: 250});

[/code]

In this example, we attach a waypoint to each article (the callout box) and trigger the blur-focus when we reach each callout box. We add 250px of offset to the top of each article, so the triggering event happens when the item is 250 pixels down the page – not when it first comes into view. This technique of triggering an effect or animation can be added to any page with a few lines of code.

Paul Weinert
Author

Paul Weinert is our founder, managing principal and spirit animal. He’s one of those odd people you meet that was born in Portland, grew up here and still lives here for some reason. If you had two words to describe Paul after meeting him, we’d bet you’d use “charmingly quirky”.

Paul started GRAYBOX in February 2009, and for the first four years, GRAYBOX had a blend of a contract staffing firm and a traditional agency. GRAYBOX then hired our first employees in 2012 and has been growing ever since. Professionally, Paul has a background in internet business consulting, working especially with mid-market ecommerce, healthcare, and tech companies. He worked as a user experience designer, web developer and internet marketer. Nowadays, Paul serves as our company visionary, team mentor and head of executive leadership — Paul is extremely proud of the entire team and the company. He’s constantly humbled by the team’s awesomeness and the caring community that’s sprung up from his initial ideas.

Beyond GRAYBOX, Paul is married, has two young boys and lives in NE Portland. He’s also an active foster parent, mentors other local entrepreneurs, and volunteers on local non-profit boards. Businesswise, aside from GRAYBOX, Paul has started a few other businesses and is an active investor in the local startup scene.

For the sheer joy of it, let’s play 2 truths and a lie:

  1. Paul firmly believes that any activity would be better if on a boat.
  2. Other than this whole Internet thing, Paul has basically no other skills or expertise in anything.
  3. Paul is rare unicorn, actually born and raised in Portland.