via http://bravecadet.com/post/5131261236/mental-pipco-treveis-fg
Archive for the ‘Google Reader’ Category
Are Antidepressants Just Placebos with Side Effects?
I have first-hand experience of the devastation of depression, in myself and those close to me. Although I have been tempted to try antidepressants, I've never done so. Of course, like everyone reading this column, I know many people who have been treated with antidepressants--not surprisingly, because according to a 2005 survey, one in 10 Americans are now under such treatment. Some people I know have greatly benefited from their treatment. Others never find adequate relief, or they experience annoying side effects--such as mania, insomnia, emotional flatness or loss of libido--so they keep trying different drugs, often in combination with psychotherapy. One chronically depressed friend has tried, unsuccessfully, to stop taking his medications, but he experienced a surge of depression worse than the one that led him to seek treatment. He accepts that he will probably need to take antidepressants for the rest of his life. [More]
Photo: Father and son at first and last Space Shuttle launches, 30 years apart
"Father and Son: STS-1 and STS-135," a photo by Chris Bray, who is the younger of the two in these side-by-side captures from the very first shuttle launch thirty years ago, and the final one, last Friday. "The picture we waited 30 years to complete."
(Flickr, via Reddit and Laughing Squid.)
Over The Past 4 Years News Corp Generated $10.4 Billion In Profits And Received $4.8 Billion In “Taxes” From The IRS
Call it the gift that keeps on giving (if one is a corporation that is): the US Tax system, so effective at extracting income tax from America's working class, is just as "effective" at redistributing said income tax at the corporate level. Case in point: News Corp, which after generating $10.4 billion in profits over the past 4 years, and which would have been expected to pay the IRS $3.6 billion at the statutory corporate tax rate, instead received $4.6 billion back from Uncle Sam. Bottom line: Murdoch's corporation had a cash paid tax rate of -46% between 2007 and 2010. The culrpit: two little somethings called Deferred Tax Assets and Net Operating Loss Carry-forwards.
The chart below shows News Corp's profits and annual cash tax receipts.
Is it all just such IRS tax loopholes as deferred tax assets and NOL carryforward? Not entirely. Reuters explains:
How does Murdoch make money off the tax system? There are three basic elements, disclosure statements show.
One is the aggressive use of intra-company transactions that globally allocate costs to locations that impose taxes -- and profits to areas where profits can be earned tax-free.
For that Murdoch can thank laws and treaties that treat multinational corporations much more generously than working stiffs, such as those who make up the audience for his New York Post and for his British tabloids with bare-breasted women. Working stiffs have their taxes taken out of their pay before they get it, while Murdoch gets to profit now and pay taxes by-and-by.
News Corp. has 152 subsidiaries in tax havens, including 62 in the British Virgin Islands and 33 in the Caymans. Among the hundred largest U.S. companies, only Citigroup and Morgan Stanley have more tax haven subsidiaries than News Corp., a 2009 U.S. Government Accountability Office study found.
News Corp. had nearly $7 billion permanently invested offshore in 2009, money on which it does not have to pay taxes unless it brings the money back to the United States. Meanwhile, it can use that money as collateral for loans in the United States, where interest paid is a tax-deductible expense.
Granted, this practice accounts for a very modest portion of the total tax receipts. The two far greater culprits are acquired NOLs...
Buying companies with tax losses is a second way Murdoch can pocket, rather than pay, taxes. In three deals to acquire American television stations -- in 1985, 1990 and 2001 -- questions were raised about whether Murdoch entities were in compliance with American rules limiting the ownership stakes of foreign investors.
A memo, turned over to the Federal Communications Commission during one of these inquiries, showed that in 1990 Murdoch's advisers were, in the words of Michael Gardner, an outside counsel to News Corp., "in agreement that it is paramount to avoid any corporate restructuring which would potentially invite reexamination of Fox TV's ownership structure" by the FCC.
In 1995, the FCC general counsel, William Kennard, said that a two-year investigation requested by rival NBC and the National Association for the Advancement of Colored People (NAACP) found that "Fox did not clearly or explicitly disclose" News Corp.'s ownership stake in American television stations as required. However, Kennard said this lack of candor was insufficient to require a hearing into whether Fox had intended to deceive the commission.
... and, yes, deferred tax assets:
Murdoch's tax lawyers are expert at maximizing the benefits of deferrals. Incurring a tax today, but paying it by-and-by can be profitable. A dollar of tax deferred for 30 years, and invested at 8 percent real growth while inflation runs 3 percent, is worth more than $10 at the end of the period, while the real value of the tax when it is ultimately paid is just 40 cents.
Last year News Corp. had net future tax assets of $3.3 billion. In the past four years News Corp. has either used up a lot of its tax benefits or had them expire. In 2007 its net tax assets were $5.7 billion.
At this point Reuters takes a rare departure from its dry factual reporting to poke some fun at the billionaire, whose empire, and reputation, is suddenly crumbling before his eyes:
Fox News, the editorial pages of his Wall Street Journal and other Murdoch outlets often rail against taxes. Their attacks on government benefits for the elderly, the sick, the jobless and children focus attention on the uses of tax dollars and away from his aggressive efforts to enjoy the benefits of civilization without paying for them.
Many other companies may follow similar practices but most of corporate America doesn't own one of the country's most powerful newspaper editorial pages.
...
Murdoch assiduously courts the powers-that-be for favorable laws and regulatory rulings. Contrast that with the rough and sometimes relentless attacks on politicians and government programs of his newspapers and his Fox News Channel.
Murdoch's news outlets can prove enormously helpful to politicians. His support boosted Hillary Clinton's 2000 campaign for the U.S. Senate from New York, helping her to beat Republican Rick Lazio. Murdoch even hosted a Clinton re-election campaign fundraiser in 2006, while restraining New York Post gossip mongers who looked on her husband as red meat in the White House.
Murdoch gets invited to weddings and celebrations of top American, British and Chinese officials. He flew Tony Blair halfway around the world to a company event in Australia when the future British prime minister was opposition leader.
Imagine how well Jesus might have done if he had put a corporate jet at Caesar's disposal. Or if he had a tabloid like the News of the World to put Caesar in fear of him.
However, in the interest of objectivity, News Corp. is merely one of many corporate transgressors who take full advantage of the massive loopholes in America's tax code. From Bloomberg.
American International Group Inc. (AIG), Citigroup Inc. (C) and General Motors Co. (GM), once the largest insurer, bank and automaker, hold a new distinction after losses forced them to take bailouts. The firms accumulated some of the biggest deferred tax assets that may lower obligations to the government that rescued them.
Losses at New York-based AIG and its subsidiaries helped rack up more than $25 billion in the assets. That’s worth more to AIG’s share price than its plane-leasing business with 933 aircraft, according to Bank of America Corp.
“They’re in the same class of GM and Citigroup in terms of the largest I’ve ever seen,†Robert Willens, an independent tax consultant in New York, said of AIG. “Any one of them is in the hall of fame of large deferred tax assets.â€
Citigroup’s $23.2 billion of carry-forwards as of Dec. 31 include benefits from net operating losses and foreign tax credits. The New York-based bank expects to use its entire U.S. federal net operating loss carry-forward this year, according to a regulatory filing. The company valued that asset at about $3.9 billion at the end of last year. Jon Diat, a spokesman for Citigroup, declined to comment.
GM reported $20.1 billion in tax carry-forwards. The automaker amassed tax assets as it posted losses from 2005 to its bankruptcy in 2009, and in some regions outside the U.S. last year. GM is poised to become the No. 1 automaker by sales this year after being passed in 2008 by Toyota Motor Corp.
The sum means the company may not pay taxes to the U.S. until 2018, Adam Jonas, a Morgan Stanley analyst, said in a July 6 research note. Jonas, who swapped GM for Ford Motor Co. as his top U.S. auto pick in the report, said the assets are worth about $9 per share, more than the value of the company’s joint ventures in China. Jim Cain, a spokesman for GM, declined to comment.
As a reminder...
AIG was rescued in 2008 in a bailout that swelled to $182.3 billion. Citigroup received $45 billion from the Treasury’s Troubled Asset Relief Program and $301 billion in guarantees on its riskiest assets. The government sold its remaining stake in the bank in December.
GM was bailed out with $49.5 billion in taxpayer funds as the government backed its bankruptcy in 2009. The Treasury reduced its stake to 33 percent last year in a share sale.
It is probably only fitting that companies that have received massive taxpayer generosity to remain in business continue their tax evasive ways and pay absolutely nothing in cash taxes (and probably, quite the inverse) for years and years. After all, who needs corporate cash: there is always the Fed's printing press to make up for any shortfalls. And non-sheltered, middle-class income tax of course.
We have a taxing problem, not just a spending problem
The Bush tax cuts were not supposed to last forever. Alan Greenspan, whose oracular endorsement was perhaps the single most decisive event in their passage, made it very clear that they were a temporary solution to a temporary surplus. “Recent data significantly raise the probability that sufficient resources will be available to undertake both debt reduction and surplus-lowering policy initiatives,†Greenspan said in 2001.
Okay, so maybe he wasn’t so clear. But everyone knew what he meant. And, broadly speaking, they agreed. We had a big surplus. It was time to do something with it. Brad DeLong, a former Clinton administration official and an economist at the University of California at Berkeley, didn’t want to see the surplus spent on tax cuts. He wanted to see it spent on public investments. “Nevertheless,†he wrote in 2001, “it is hard to disagree with Greenspan’s position that — if our future economic growth is as bright as appears likely— it will be time by the middle of this decade to do something to drastically cut the government’s surpluses.â€
Ten years later, there is no surplus. It turned out that our future economic growth wasn’t as bright as had seemed likely in 2001. That, plus $2 trillion in tax cuts and a few trillion more in wars and assorted spending, left us with large and growing deficits.
The next step, then, is obvious. The Bush tax cuts were scheduled to expire after 10 years. Congress extended them for two years in 2010, as you don’t want a massive tax increase in the middle of a deep recession. But as we look toward our future deficits, it seems we’ll need to let at least some of the tax cuts expire. Indeed, Greenspan now says we should let all of the Bush tax cuts expire.
But the Republican Party refuses to let any of them expire. And forget admitting that tax cuts meant for surpluses don’t make sense during deficits; they refuse to admit that tax cuts have anything to do with deficits at all.
It’s this belief that stands in the way of a debt deal. “We have a spending problem, not a taxing problem,†Republicans say. If the federal government defaults on Aug. 2, that sentence will be to blame. What a shame, then, that the sentence is entirely, obviously, wrong.
“I’m an ‘and’ guy, not an ‘or’ guy,†says Donald Marron, who served as an economist in George W. Bush’s White House and now leads the Brookings/Urban Tax Policy Center. If you look at the numbers, it’s easy to see why economists like Marron think we have both a spending problem and a taxing problem. In 2001, revenues were at 19.5 percent of gross domestic product and spending was at 18.6 percent of GDP. That was our surplus. In 2010, revenues were at 14.9 percent of GDP while spending was at 23.9 percent. That’s our deficit: Revenues are down and spending is up. It’s “and,†not “or.â€
If you’re worried about the deficit, then, the solution is plain: some mix of tax increases and spending cuts. If Democrats are being honest, they’ll tell you they’re worried about the deficit, but that the right time to address the deficit is after a real recovery takes hold, which means we shouldn’t begin serious deficit reduction until 2013 or later. If Republicans are being honest, they’ll tell you they’re worried about the deficit, but resisting tax increases is their top priority, because keeping taxes low means that government will shrink.
In practice, empirical analyses have found that tax rates do not drive the long-term growth in government. But it is driving Republican strategy on the budget. That’s why the GOP preferred a $2 trillion deficit reduction deal with no taxes to a $4 trillion deficit deal that would have included some taxes, but also, according to reports out of both parties, raised the Medicare eligibility age and cut Social Security benefits.
In rejecting that deal, which liberals would have loathed, Speaker of the House John Boehner (R-Ohio) might have inadvertently saved President Obama from facing a primary challenge. But more to the point, he might have locked in higher taxes down the road. Few noticed that the White House offer of $1 trillion in revenues in return for $3 trillion of spending cuts would have taken the expiration of the Bush tax cuts off of the table. That would mean the tax debate concluded this year, a time when the debt ceiling gives the GOP leverage, rather than next year, when the Bush tax cuts are set to expire and the White House has most of the leverage.
In other words: If Republicans could have agreed with Democrats now, taxes would have gone up by $1 trillion. If they can’t agree with Democrats next year, they’ll go up by more than $4 trillion. And Republicans had a better hand this year than they will next year. I expect they’ll come to wish they’d played it.
Behind The Scenes Of Nike Better World
Perhaps one of the most talked about websites in the last 12 months has been Nike Better World. It’s been featured in countless Web design galleries, and it still stands as an example of what a great idea and some clever design and development techniques can produce.
In this article, we’ll talk to the team behind Nike Better World to find out how the website was made. We’ll look at exactly how it was put together, and then use similar techniques to create our own parallax scrolling website. Finally, we’ll look at other websites that employ this technique to hopefully inspire you to build on these ideas and create your own variation.
Nike Better World
Nike Better World is a glimpse into how Nike’s brand and products are helping to promote sports and its benefits around the world. It is a website that has to be viewed in a browser (preferably a latest-generation browser, although it degrades well) rather than as a static image, because it uses JavaScript extensively to create a parallax scrolling effect.
A good deal of HTML5 is used to power this immersive brand experience and, whatever your views on Nike and its products, this website has clearly been a labor of love for the agency behind it. Although parallax scrolling effects are nothing new, few websites have been able to sew together so many different design elements so seamlessly. There is much to learn here.
An “Interactive Storytelling Experienceâ€
In our opinion, technologies are independent of concept. Our primary focus was on creating a great interactive storytelling experience.
– Widen+Kennedy
Nike turned to long-time collaborator Widen+Kennedy (W+K), one of the largest independent advertising agencies in the world, to put together a team of four people who would create Nike Better World: Seth Weisfeld was the interactive creative director, Ryan Bolls produced, while Ian Coyle and Duane King worked on the design and interaction.
I started by asking the team whether the initial concept for the website pointed to the technologies they would use. As the quote above reveals, they in fact always start by focusing on the concept. This is a great point. Too many of us read about a wonderful new technique and then craft an idea around it. W+K walk in the opposite direction: they create the idea first, and sculpt the available technologies around it.
So, with the concept decided on, did they consciously do the first build as an “HTML5 website,†or did this decision come later?
There were some considerations that led us to HTML5. We knew we wanted to have a mobile- and tablet-friendly version. And we liked the idea of being able to design and build the creative only once to reach all the screens we needed to be on. HTML5 offered a great balance of creativity and technology for us to communicate the Nike Better World brand message in a fresh and compelling way.
– W+K
HTML5 is still not fully supported in all browsers (read “in IEâ€) without JavaScript polyfills, so just how cross-browser compatible did the website have to be?
The primary technical objectives were for the site to be lightweight, optimized for both Web and devices, as well as to be scalable for future ideas and platforms.
– W+K
To achieve these goals, the website leans on JavaScript for much of the interactivity and scrolling effects. Later, we’ll look at how to create our own parallax scrolling effect with CSS and jQuery. But first, we should start with the template and HTML.
The Starting Boilerplate
It’s worth pointing out the obvious first: Nike Better World is original work and should not be copied. However, we can look at how the website was put together and learn from those techniques. We can also look at other websites that employ parallax scrolling and then create our own page, with our own code and method, and build on these effects.
I asked W+K if it starts with a template.
We started without a framework, with only reset styles. In certain cases, particularly with experimental interfaces, it ensures that complete control of implementation lies in your hands.
– W+K
If you look through some of the code on Nike Better World, you’ll see some fairly advanced JavaScript in a class-like structure. However, for our purposes, let’s keep things fairly simple and rely on HTML5 Boilerplate as our starting point.
Download HTML5 Boilerplate. The “stripped†version will do. You may want to delete some files if you know you won’t be using them (crossdomain.xml, the test folder, etc.).
As you’ll see from the source code (see the final code below), our page is made up of four sections, all of which follow a similar pattern. Let’s look at one individual section:
<section class="story" id="first" data-speed="8" data-type="background"> <div data-type="sprite" data-offsetY="950" data-Xposition="25%" data-speed="2"></div> <article> <h2>Background Only</h2> <div> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> </div> </article> </section>
I’m not sure this is the best, most semantic use of those HTML5 tags, but it’s what we need to make this effect work. Normally, a section has a heading, so, arguably, the section should be a div and the article should be a section. However, as W+K points out, the HTML5 spec is still young and open to interpretation:
HTML5 is still an emerging standard, particularly in implementation. A lot of thought was given to semantics. Some decisions follow the HTML5 spec literally, while others deviate. As with any new technology, the first to use it in real-world projects are the ones who really shape it for the future.
– W+K
This is a refreshing interpretation. Projects like Nike Better World are an opportunity to “reality check†an emerging standard and, for the conscientious among us, to provide feedback on the spec.
In short, is the theory of the spec practical? W-K elaborates:
We use the article tag for pieces of content that can (and should) be individually (or as a group) syndicated. Each “story†is an article. We chose divs to wrap main content. We took the most liberty with the section tag, as we feel its best definition in the spec is as chapters of content, be it globally.
– W+K
As an aside (no pun intended!), HTML5 Doctor has begun a series of mark-up debates called Simplequizes, which are always interesting and illustrate that there is rarely one mark-up solution for any problem. Make sure to check them out.
In style.css, we can add a background to our section with the following code:
section { background: url(../images/slide1a.jpg) 50% 0 no-repeat fixed; }
We should also give our sections a height and width, so that the background images are visible:
.story { height: 1000px; padding: 0; margin: 0; width: 100%; max-width: 1920px; position: relative; margin: 0 auto; }
I’ve set the height of all our sections to 1000 pixels, but you can change this to suit your content. You can also change it on a per-section basis.
We have also made sure that the maximum width of the section is the maximum width of the background (1920 pixels), and we have specified a relative position so that we can absolutely position its children.
Here’s the page before adding JavaScript. It’s worth digging into the source code to see how we’ve duplicated the sections in the HTML and CSS.
Even with this code alone, we already have a pleasing effect as we scroll down the page. We’re on our way.
The HTML5 Data Attribute
Before looking at parallax scrolling, we need to understand the new data
attribute, which is used extensively throughout the HTML above.
Back in the good old days, we would shove any data that we wanted to be associated with an element into the rel
attribute. If, for example, we needed to make the language of a story’s content accessible to JavaScript, you might have seen mark-up like this:
<article class='story' id="introduction" rel="en-us"></article>
Sometimes complex DOM manipulation requires more information than a rel
can contain, and in the past I’ve stuffed information into the class
attribute so that I could access it. Not any more!
The team at W+K had the same issue, and it used the data
attribute throughout Nike Better World:
The
data
attribute is one of the most important attributes of HTML5. It allowed us to separate mark-up, CSS and JavaScript into a much cleaner workflow. Websites such as this, with high levels of interaction, are almost application-like behind the scenes, and thedata
attribute allows for a cleaner application framework.– W+K
So, what is the data attribute? You can read about it in the official spec, which defines it as follows:
Custom data attributes are intended to store custom data private to the page or application, for which there are no more appropriate attributes or elements.
– W+K
In other words, any attribute prefixed with data- will be treated as storage for private data; it does not affect the mark-up, and the user cannot see it. Our previous example can now be rewritten as:
<article class='story' id="introduction" data-language="en-us"></article>
The other good news is that you can use more than one data
attribute per element, which is exactly what we’re doing in our parallax example. You may have spotted the following:
<div data-type="sprite" data-offsetY="100" data-Xposition="50%" data-speed="2"></div>
Here, we are storing four pieces of information: the x and y data offsets and the data speed, and we are also marking this element as a data type. By testing for the existence of data-type
in the JavaScript, we can now manipulate these elements as we wish.
Parallax Scrolling
On our page, three things create the parallax scrolling illusion:
- The background scrolls at the slowest rate,
- Any sprites scroll slightly faster than the background,
- Any section content scrolls at the same speed as the window.
With three objects all scrolling at different speeds, we have created a beautiful parallax effect.
It goes without saying that we don’t need to worry about the third because the browser will take care of that for us! So, let’s start with the background scroll and some initial jQuery.
$(document).ready(function(){ // Cache the Window object $window = $(window);
// Cache the Y offset and the speed $('[data-type]').each(function() { $(this).data('offsetY', parseInt($(this).attr('data-offsetY'))); $(this).data('speed', $(this).attr('data-speed')); });
// For each element that has a data-type attribute $('section[data-type="background"]').each(function(){ // Store some variables based on where we are $(this).data('speed', parseInt($(this).attr('data-speed'))); var $self = $(this), offsetCoords = $self.offset(), topOffset = offsetCoords.top; $(window).scroll(function(){ // The magic will happen in here! }); // window scroll }); // each data-type }); // document ready
First, we have our trusty jQuery document ready
function, to ensure that the DOM is ready for processing. Next, we cache the browser window object, which we will refer to quite often, and call it $window
. (I like to prefix jQuery objects with $
so that I can easily see what is an object and what is a variable.)
We also use the jQuery .data
method to attach the Y offset (explained later) and the scrolling speed of the background to each element. Again, this is a form of caching that will speed things up and make the code more readable.
We then iterate through each section that has a data
attribute of data-type="background"
with the following:
$('section[data-type="background"]').each(function(){}
Already we can see how useful data attributes are for storing multiple pieces of data about an object that we wish to use in JavaScript.
Inside the .each
function, we can start to build up a picture of what needs to be done. For each element, we need to grab some variables:
// Store some variables based on where we are var $self = $(this), offsetCoords = $self.offset(), topOffset = offsetCoords.top;
We cache the element as $self
(again, using the $
notation because it’s a jQuery object). Next, we store the offset()
of the element in offsetCoords
and then grab the top offset using the .top
property of offset()
.
Finally, we set up the window scroll
event, which fires whenever the user moves the scroll bar or hits an arrow key (or moves the trackpad or swipes their finger, etc.).
We need to do two more things: check that the element is in view and, if it is, scroll it. We test whether it’s in view using the following code:
// If this section is in view if ( ($.Window.scrollTop() + $.Window.height()) > ($offsetCoords.top) && ( ($offsetCoords.top + $self.height()) > $.Window.scrollTop() ) ) { }
The first condition checks whether the very top of the element has scrolled into view at the very bottom of the browser window.
The second condition checks whether the very bottom of the element has scrolled past the very top of the browser window.
You could use this method to check whether any element is in view. It’s sometimes useful (and quicker) to process elements only when the user can see them, rather than when they’re off screen.
So, we now know that some part of the section element with a data-type
attribute is in view. We can now scroll the background. The trick here is to scroll the background slower or faster than the browser window is scrolling. This is what creates the parallax effect.
Here’s the code:
// Scroll the background at var speed // the yPos is a negative value because we're scrolling it UP! var yPos = -($window.scrollTop() / $self.data('speed')); // If this element has a Y offset then add it on if ($self.data('offsetY')) { yPos += $self.data('offsetY'); } // Put together our final background position var coords = '50% '+ yPos + 'px'; // Move the background $self.css({ backgroundPosition: coords });
The y
position is calculated by dividing the distance that the user has scrolled from the top of the window by the speed. The higher the speed, the slower the scroll.
Next, we check whether there is a y
offset to apply to the background. Because the amount that the background scrolls is a function of how far the window has scrolled, the further down the page we are, the more the background has moved. This can lead to a situation in which the background starts to disappear up the page, leaving a white (or whatever color your background is) gap at the bottom of each section.
The way to combat this is to give those backgrounds an offset that pushes them down the page an extra few hundred pixels. The only way to find out this magic offset number is by experimenting in the browser. I wish it was more scientific than this, but this offset really does depend on the height of the browser window, the distance scrolled, the height of your sections and the height of your background images. You could perhaps write some JavaScript to calculate this, but to me this seems like overkill. Two minutes experimenting in Firebug yields the same result.
The next line defines a variable coords
to store the coordinates of the background. The x
position is always the same: 50%. This was the value we set in the CSS, and we won’t change it because we don’t want the element to scroll sideways. Of course, you’re welcome to change it if you want the background to scroll sideways as the user scrolls up, perhaps to reveal something.
(Making the speed a negative number for slower scrolling might make more sense, but then you’d have to divide by -$speed
. Two negatives seems a little too abstract for this simple demonstration.)
Finally, we use the .css
method to apply this new background position. Et voila: parallax scrolling!
Here’s the code in full:
// Cache the Window object $window = $(window); // Cache the Y offset and the speed of each sprite $('[data-type]').each(function() { $(this).data('offsetY', parseInt($(this).attr('data-offsetY'))); $(this).data('speed', $(this).attr('data-speed')); }); // For each element that has a data-type attribute $('section[data-type="background"]').each(function(){ // Store some variables based on where we are var $self = $(this), offsetCoords = $self.offset(), topOffset = offsetCoords.top; $(window).scroll(function(){ // If this section is in view if ( ($window.scrollTop() + $window.height()) > (topOffset) && ( (topOffset + $self.height()) > $window.scrollTop() ) ) { // Scroll the background at var speed // the yPos is a negative value because we're scrolling it UP! var yPos = -($window.scrollTop() / $self.data('speed')); // If this element has a Y offset then add it on if ($self.data('offsetY')) { yPos += $self.data('offsetY'); } // Put together our final background position var coords = '50% '+ yPos + 'px'; // Move the background $self.css({ backgroundPosition: coords }); }; // in view }); // window scroll }); // each data-type
Of course, what we’ve done so far is quite a bit simpler than what’s on Nike Better World. W+K admits that the parallax scrolling threw it some challenges:
The parallax scrolling presented a few small challenges in cross-browser compatibility. It took a little experimenting to ensure the best scrolling experience. In the end, it was less about the actual parallax effect and more about synchronized masking of layers during transitions.
– W+K
W+K also reveals how it maintained a fast loading and paint speed by choosing its tools wisely:
The key to maintaining faster speeds is to use native CSS where possible, because DOM manipulation slows down rendering, particularly on older browsers and processors.
– W+K
For example, the “More†button below spins on hover, an effect achieved with CSS3. In browsers that don’t support CSS3 transforms, the purpose of the graphic is still obvious.
Adding More Elements
Of course, one of the other common features of parallax scrolling is that multiple items on the page scroll. So far, we have two elements that move independently of each other: the first is the page itself, which scrolls when the user moves the scroll bar, and the second is the background, which now scrolls at at slower rate thanks to the jQuery above and the background-position
CSS attribute.
For many pages, this would be enough. It would be a lovely effect for the background of, say, a blog. However, Nike and others push it further by adding elements that move at a different speed than that of the page and background. To make things easy — well, easier — I’m going to call these new elements sprites.
Here’s the HTML:
<div id="smashinglogo" data-type="sprite" data-offsetY="1200" data-Xposition="25%" data-speed="2"></div>
Put this just before the closing </article>
tag, so that it appears behind the contents of <article>
. First, we give the div an id so that we can refer to it specifically in the CSS. Then we use our HTML5 data
attribute to store a few values:
- The status of a
sprite
, - A
y
(vertical) offset of 1200 pixels, - An
x
(horizontal) position as a percentage, - A scrolling speed.
We give the x
position of the sprite a percentage value because it is relative to the size of the viewport. If we gave it an absolute value, which you’re welcome to try, there’s a chance it could slide out of view on either the left or right side.
Now about that y
offset…
Inception
This is the bit that’s going to mess with your noodle and is perhaps the hardest part of the process to grasp.
Thanks to the logic in the JavaScript, the sprite won’t move until the parent section is in view. When it does move, it will move at (in this case) half the speed. You need the vertical position, then, to account for this slower movement; elements need to be placed higher up if they will be scrolling more slowly and, therefore, moving less on the y
axis.
We don’t know how far the user has to scroll before the section appears at the bottom of the page. We could use JavaScript to read the viewport size and then do some calculations based on how far down the page the section is positioned. But that is already sounding too complicated. There is an easier way.
What we do know is how far the user has scrolled before the current section is flush with the top of the viewport: they have scrolled the y
offset of that particular section. (Put another way, they have scrolled the height of all of the elements above the current one.)
So, if there are four sections, each 1000 pixels high, and the third section is at the top of the viewport, then the user must have scrolled 2000 pixels, because this is the total height of the preceding sections.
If we want our sprite to appear 200 pixels from the top of its parent section, you’d figure that the total vertical offset we give it should be 2200 pixels. But it’s not, because this sprite has speed, and this speed (in our example) is a function of how far the page has been scrolled.
Let’s assume that the speed is set as 2
, which is half the speed at which the page is scrolling. When the section is fully in view, then the window has scrolled 2000 pixels. But we divide this by the speed (2) to get 1000 pixels. If we want the sprite to appear 200 pixels from the top, then we need to add 200 to 1000, giving us 200 pixels. Therefore, the offset is 1200. In the JavaScript, this number is inverted to -1200 because we are pushing the background-position
down off the bottom of the page.
Here’s a sketch to show this in action.
This is one of those concepts that is easier to understand when you view the page and source code and scroll around with the console open in Firebug or Developer Tools.
The JavaScript looks like this:
// Check for other sprites in this section $('[data-type="sprite"]', $self).each(function() { // Cache the sprite $sprite = $(this); // Use the same calculation to work out how far to scroll the sprite var yPos = -($.Window.scrollTop() / $sprite.data('speed')); var coords = $sprite.data('Xposition') + ' ' + (yPos + $sprite.data('offsetY')) + 'px'; $sprite.css({ backgroundPosition: coords }); }); // sprites
HTML5 Video
One criticism levelled at Nike Better World is that it didn’t use HTML5 video. HTML5 is still not fully supported across browsers (I’m looking at you, Internet Explorer), but for the purposes of this article, we’ll embrace HTML5 video, thanks to the lovely folks at Vimeo and Yum Yum London.
But we can’t set a video as a background element, so we have a new challenge: how to position and scroll this new sprite?
Well, there are three ways:
- We could change its
margin-top
property within its parent section; - We could make it a
position: absolute
element and change its top property when its parent section comes into view; - We could define it as
position: fixed
and set itstop
property relative to the viewport.
Because we already have code for the third, let’s grab the low-hanging fruit and adapt it to our purposes.
Here’s the HTML we’ll use, which I’ve placed after the closing </article>
tag:
<video controls width="480" width="320" data-type="video" data-offsetY="2500" data-speed="1.5"> <source src="video/parallelparking.theora.ogv" type="video/ogg" /> <source src="video/parallelparking.mp4" type="video/mp4" /> <source src="video/parallelparking.webm" type="video/webm" /> </video>
First, we’ve opened our HTML5 video element and defined its width and height. We then set a new data-type
state, video
, and defined our y
offset and the speed at which the element scrolls. It’s worth nothing that some experimentation is needed here to make sure the video is positioned correctly. Because it’s a position: fixed
element, it will scroll on top of all other elements on the page. You can’t cater to every viewport at every screen resolution, but you can play around to get the best compromise for all browser sizes (See “Bespoke to Broke†below).
The CSS for the video element looks like this:
video { position: fixed; left: 50%; z-index: 1;}
I’ve positioned the video 50%
from the left so that it moves when the browser’s size is changed. I’ve also given it a z-index: 1
. This z-index prevents the video element from causing rendering problems with neighbouring sections.
And now for the JavaScript! This code should be familiar to you:
// Check for any Videos that need scrolling $('[data-type="video"]', $self).each(function() { // Cache the sprite $video = $(this); // Use the same calculation to work out how far to scroll the sprite var yPos = -($window.scrollTop() / $video.data('speed')); var coords = (yPos + $video.data('offsetY')) + 'px'; $video.css({ top: coords }); }); // video
And there you have it! A parallax scrolling HTML5 video.
Bespoke or Broke
Of course, every design is different, which means that your code for your design will be unique. The JavaScript above will plug and play, but you will need to experiment with values for the y
offset to get the effect you want. Different viewport sizes means that users will scroll different amounts to get to each section, and this in turn affects how far your elements scroll. I can’t control it any more than you can, so you have to pick a happy medium. Even Nike Better World suffers when the viewport’s vertical axis stretches beyond the height of the background images.
I asked W+K how it decides which effects to power with JavaScript and which are better suited to modern CSS techniques:
Key points that required complex interaction relied on JavaScript, while visual-only interactivity relied on CSS3. Additionally, fewer browsers support native CSS3 techniques, so items that were more important to cross-browser compatibility were controlled via JavaScript as well.
– W+K
This is a wonderful example of “real-world design.†So often we are bamboozled with amazing new CSS effects, and we make websites that sneer at older browsers. The truth is, for most commercial websites and indeed for websites like Nike Better World that target the biggest audience possible, stepping back and considering how best to serve your visitors is important.
W+K explains further:
We started by creating the best possible version, but always kept the needs of all browsers in mind. Interactive storytelling must balance design and technology to be successful. A great website usable in one or two browsers ultimately fails if you want to engage a wide audience.
– W+K
And Internet Explorer?!
IE was launched in tandem with the primary site. Only IE6 experienced challenges, and as a deprecated browser, it gracefully degrades.
– W+K
The Final Code
The code snippets in this piece hopefully go some way to explaining the techniques required for a parallax scrolling effect. You can extend them further to scroll multiple elements in a section at different speeds, or even scroll elements sideways!
Feel free to grab the full source code from GitHub, and adapt it as you see fit. Don’t forget to let us know what you’ve done, so that others can learn from your work.
Of course, remember that manipulating huge images and multiple sprites with JavaScript can have huge performance drawbacks. As Keith Clark recently tweeted:
Test, test and test again. Optimize your images, and be aware that you may have to compromise to support all browsers and operating systems.
Tell A Story
Above and beyond the technical wizardry of parallax websites — some of the best of which are listed below — the common thread that each seems to embody is story. That’s what makes them great.
I asked W+K what it learned from the project:
That a strong voice, simplicity and beauty are integral to a great interactive storytelling experience. We often hear things like “content is king, and technology is just a tool to deliver it,†but when you’re able to successfully combine a powerful message with a compelling execution, it creates an experience that people really respond to and want to spend time with.
– W+K
We really have just scratched the surface of the work that goes into a website like Nike Better World. The devil is in the details, and it doesn’t take long to see how much detail goes into both the design and development.
However, if you have a compelling story to tell and you’re not afraid of a little JavaScript and some mind-bending offset calculations, then a parallax website might just be the way to communicate your message to the world.
More Examples
Nike wasn’t the first and won’t be the last. Here are some other great examples of parallax scrolling:
If you’ve seen or built a great parallax website, please let us know about it in the comments.
… If you need any more encouragement to create a website as compelling as these, here’s what the team at W+K used to put together Nike Better World: MacBook Air 13″, Canon 5D Mark II, Coda, Adobe Photoshop and Adobe Illustrator.
Thanks
Putting together this article took the cooperation of a number of people. I’d like to thank Seth, Ryan, Ian and Duane for answering my questions; Katie Abrahamson at W+K for her patience and for helping coordinate the interview; and Nike for allowing us to dissect its website so that others could learn.
(al)
© Richard Shepherd for Smashing Magazine, 2011.
The fanless spinning heatsink: more efficient and immune to dust
There’s a fundamental flaw with fan-and-heatsink cooling systems: no matter how hard the fan blows, a boundary layer of motionless, highly-insulating air remains on the heatsink. You can increase the size of the heatsink and you can blow more air, but ultimately the boundary layer prevents the system from being efficient; it’s simply a physical limitation of fan-and-heatsink cooling systems in specific, and every kind of air-cooled heat exchanger in general, including air conditioning and refrigeration units.
But what if you did away with the fan? What if the heatsink itself rotated? Well, believe it or not, rotating the heat exchanger obliterates the boundary layer, removes the need for a fan, and it’s so efficient that it can operate at low and very quiet speeds. Ladies and gentlemen, I give you the Air Bearing Heat Exchanger [PDF]. Developed by Jeff Koplow, a researcher at the US government’s Sandia National Laboratories, the new heatsink (which has also been dubbed the “Sandia Coolerâ€) basically resembles a big, metal fan. The cooler consists of a static metal baseplate, which is connected to the CPU, GPU, or other hot object, and a finned, rotating heat exchanger that are cushioned by a thin (0.001-inch) layer of air. As the metal blades spin, centrifugal force kicks up the air and throws it up and outwards, much like an impeller, creating a cooling effect.
This new technique is so efficient that if these heat exchangers can find widespread adoption in computers and air conditioning units, Koplow estimates that the total US electricity consumption could drop by 7%. Furthermore, if you’re a computer geek, there’s another big advantage of the Air Bearing Heat Exchanger: it’s intrinsically immune to the build up of dust and detritus. The Sandia Cooler may also be the technology that smashes down the “Thermal Brick Wall†that is preventing computer chips from moving beyond 3GHz.
So when can you get your hands on one? Koplow is now working on a design that can be mass-produced — and hopefully he’ll soon be able to bring this awesome piece of technology to market.
Read more at New Scientist or read the research paper
BLOG – The Final Image
Here we go again.... another movie-themed tumblr:Â The Final Image. I bet you can guess what the concept is.
Movies pictured - Big, Edward Scissorhands, 9 to 5, 12 Angry Men, Adaptation, Almost Famous, Monsters Inc., The Others, Black Swan, Annie Hall, Rain Man, Titanic, American Graffiti, A Place in the Sun, Beetlejuice, Blue Valentine, Ferris Bueller's Day Off, Gosford Park, How to Marry a Millionaire, Brokeback Mountain, Inception, Good Will Hunting, Cry Baby, Jaws, Dirty Dancing, Moulin Rouge, Grease, Groundhog Day, Mystic River, Romancing the Stone, The Sound of Music, The Shawshank Redemption, Kramer vs. Kramer, The Graduate, The King's Speech, The Departed, Toy Story, Interview with the Vampire, Eternal Sunshine of the Spotless Mind, Manhattan, The Muppets Take Manhattan, The Shining, Up, Working Girl, Willy Wonka & the Chocolate Factory