Tuesday, February 1, 2011

iScroll 3.0 Select Box Hacks

iScroll is pretty neat. It was created by cubiq as an attempt to create a workaround for position: fixed on iOS. Sencha Touch has a much more complete solution, but as a simple solution iScroll works fairly well. 

This could be a great time to rant about how mobile safari is the new IE6, and how having to use JavaScript to fix issues that have already been fixed on the web for a long time is ridiculous. (Seriously, just let position: fixed work as long as the viewport and zoom-levels are set properly.) 

Check out the code here:
http://code.google.com/p/iscroll-js/

Anyway, look no further than iScroll.....unless you want to use a select box in the scroller.

I followed this thread about the problem here:
http://code.google.com/p/iscroll-js/issues/detail?id=14

And finally found a solution here:
http://groups.google.com/group/iscroll/browse_thread/thread/5b2fbad6aa667907

Here is my select box:


And it all seems pretty good with one additional problem. It seems that the screen gets nudged down just a little bit when you select things, so I had to add this one bit of JavaScript to bring it back to the top after the we choose our item from the select box.

document.getElementById("showing").addEventListener("change", scrollToTop);

function scrollToTop() {
  window.scrollTo(0,1);
}


The result looks something like this (everything under the sort by stuff scrolls):

No comments:

Post a Comment