[Pro] Apple Store Cart effect

Here’s a little smidge of JavaScript to emulate the positioning effect of the shopping cart in the Apple Store. If you’ve used that site before, you may have noticed that when you scroll your browser down, the cart changes position to stay in view. It starts out at some position relative to the top of the screen, but as you scroll the tall page downward, it seems to stick about 10px from the browser window top and stay there until you scroll back up to the top of the page. This is surprisingly easy to do with Prototype.js.

Make a new page, and put a bunch of tall content on it. Then draw a new HTML box somewhere else on the page. (I put mine near the same spot where the Apple cart lives; on the right, about 200px from the top. Make a note of the name of this box. You can fill it with a color, or put any content in it you like, just so you can see it.

Apply Protaculous to the page, choose prototype-packed as the library, and paste the following into the top Function Body editor:

var sticker = $('item1');
var origin = sticker.cumulativeOffset()['top'];
var offset = 10;
Event.observe(window,'scroll', function(evt){
	var scrolled = document.viewport.getScrollOffsets()[1];
	if(scrolled >= (origin - offset)){
		if(Prototype.Browser.IE){
			sticker.setStyle({"top":(scrolled + offset) + "px"});
		}else{
			sticker.setStyle('position:fixed; top:' + offset + 'px;');
		}
	}else{
		sticker.setStyle('position:absolute; top:' + origin + 'px;');
	}
});

Naturally, change ‘item1’ in this code to be the actual ID of your HTML box. Also, if you’re using the RPL Action on this page, be sure to apply the Remove from RPL Action to this box, or the effect will fail.

Preview, and scroll your page. You’ll see that the box you’ve set to be the “sticker” will never get any further than 10px from the top of the window, no matter how far you scroll. And when you scroll back down, it will return to its original spot on the page.

There’s a shim in here for IE, which doesn’t (except for IE 9, maybe 8 in Standards mode) support position:fixed. This shimmed effect will never be as smooth as the standards-compliant browsers, because it has to wait until the browser updates the JavaScript thread with the current window position, so there may be some visual stutter. The window will end up stuck in the right place, though.

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I just thought of a way to test for position:fixed support.

var sticker = $('item1');
var origin = sticker.cumulativeOffset()['top'];
var offset = 10;
var test = new Element('div',{style:'position:fixed'});
var cantBeFixed = (test.style.position.toLowerCase() != 'fixed');
Event.observe(window,'scroll', function(evt){
    var scrolled = document.viewport.getScrollOffsets()[1];
    if(scrolled >= (origin - offset)){
        if(cantBeFixed){
            sticker.setStyle({"top":(scrolled + offset) + "px"});
        }else{
            sticker.setStyle('position:fixed; top:' + offset + 'px;');
        }
    }else{
        sticker.setStyle('position:absolute; top:' + origin + 'px;');
    }
});

So this no longer relies on browser sniffing to decide which method to use. Anyone whose browser supports position:fixed will get the silky-smooth browser-native effect.

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Walter,

I tried your to follow your instructions but to no avail. When you have a chance, can you take a peek at the page to see what I did wrong. Here is the link - http://goo.gl/tecOW

Thanking you in advance. I think it is absolutely brilliant to be able to come up with this - that may seem to be a bit of a suck-up but still, it is brilliant!
Thanks,

Bryan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

You have to make your HTML “cart” element as a layer, not as a table
cell. Click once on the box, then check the Layer checkbox in the
Inspector.

Walter

On Mar 18, 2011, at 3:55 PM, Bryan Irvine wrote:

Hi Walter,

I tried your to follow your instructions but to no avail. When you
have a chance, can you take a peek at the page to see what I did
wrong. Here is the link - http://goo.gl/tecOW

Thanking you in advance. I think it is absolutely brilliant to be
able to come up with this - that may seem to be a bit of a suck-up
but still, it is brilliant!
Thanks,

Bryan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Walter,

That did the trick but i guess you already knew it would!

The first time I did it, the shopping cart jumped to the centre of the page. I switched the page alignment to “left” and it worked beautifully. I inserted links to other pages as I want make this a menu.

Once again, thank you!

Bryan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Walter,

The code is great! I’ve tried it with html, graphics, grouped items even had grouped graphic items on the left side and right side with an html box overlaid in between them and it still worked perfectly. Also, I tested it chrome, firefox, ie7 and safari without problems.

The only hiccup is that the above works when the page is aligned “left”. When aligned “centre” is selected, the floating.

Bryan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I’m curious, then. What happens on this same page if you draw an HTML box and set it to position:fixed with the Inspector?

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Walter - I can see the subtle difference between this and position:fixed but is is there a workaround for iOS devices?

David


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Try this (might not work, I haven’t had much luck with this effect on iPad).

var cantBeFixed = (Prototype.Browser.MobileSafari || 
    test.style.position.toLowerCase() != 'fixed');

Use that in the above in place of the line which begins with car cantBeFixed.

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Walter that worked http://www.deltadesign.co/examples/floater.html

Not quite the same as in normal Safari but it does leap into the correct position albeit a bit jumpy - but I could live with that.

David


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks I go for it,… KC

On Mar 20, 2011, at 2:00 PM, DeltaDave wrote:

Thanks Walter that worked http://www.deltadesign.co/examples/
floater.html

Not quite the same as in normal Safari but it does leap into the
correct position albeit a bit jumpy - but I could live with that.

David


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I had a look at the Apple Store on the iPad, and they simply don’t
even try there. They just let the cart stay wherever it is on the
page, and don’t try to do the clever “keep it in view” thing at all.
Keeps it from being jumpy, etc.

Walter

On Mar 20, 2011, at 2:00 PM, DeltaDave wrote:

Thanks Walter that worked http://www.deltadesign.co/examples/floater.html

Not quite the same as in normal Safari but it does leap into the
correct position albeit a bit jumpy - but I could live with that.

David


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Have this fix element since a few
years on that page fixed in window:


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Forgot to say: it even works with menus.
http://www.xpress4you.ch/


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hate to tell you Tom but the xpress4you site crashes Mobile Safari on my iPad and iPhone - latest versions

David


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

And on the werbedruck site the fixed in window doesn’t work

D


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

David the mobile version construction is in progress …

But they are not crashing here on my mobile stuff … thats strange. 4.3 no jailbreak


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

My iPad and iPhone are both vanilla versions of 4.3

D


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi all,

how would the experts judge about the following small example?

http://www.kimmich-dm.de/testings/scrolling-side.html

I know this is jQuery, but that’s in fact the only negative about this cause as far as tested it even works on the iTechnologie (iPhone tested).

Maybe somebody showing on how to add a jQuery no-conflict?

Cheers

Thomas


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Please, I am asking as nicely as I know how – remove the ‘resize
window to full screen’ badness from this site.

This is as hostile an act as blaring music in the background when the
page loads. Very. Very. Hostile.

I have an enormous pair of screens. I have several to dozens of
browser windows open at the same time. I never browse full screen and
I don’t plan to start. Further, this page is designed to fit a much
smaller screen than mine, and looks kinda lonely with all of its
content stretched across thousands of pixels.

The dimensions and position of a browser window are off limits to a
Web page, in my opinion. Just because you CAN do a thing doesn’t mean
you SHOULD.

Walter

On Mar 22, 2011, at 4:00 AM, TomP wrote:

Forgot to say: it even works with menus.
http://www.xpress4you.ch/


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options