I have a stack of 'pages' that I'm trying to move on mousewheel, such that the top one moves more than the one underneath it, etc. They're position: absolute
, and currently I'm adjusting the CSS top
to move them around, but it is veeery slow and janky.
EDIT: took down demo, problem solved.
Relevant code:
window.onScroll = (e, delta) ->
e.preventDefault()
minHeight = 5
maxHeight = 800
top_scale = 50
second_scale = 5
third_scale = 1
stack = $('.card_stack').first().children()
top = $(stack[stack.length - 1])
second = $(stack[stack.length - 2])
third = $(stack[stack.length - 3])
for pair in [[top, top_scale], [second, second_scale], [third, third_scale]]
pair[0].css('top', parseInt(pair[0].css('top'), 10) + delta*pair[1] + 'px')
$(window).mousewheel(window.onScroll) # jQuery mousewheel plugin
I tried looking at this in the Frames tab of Chrome to figure out what's so slow, and got this: https://dl.dropbox.com/u/407870/static/Screen%20Shot%202012-11-20%20at%201.44.33%20PM.png
It looks like there's not really much going on, but maybe I'm missing something. A previous, unanswered question related to the Frames problem I'm having: Web inspector profiling with "Frames": finding the cause of performance problems when nothing appears in the timeline
I know there are a bunch of other things that should be cleaned up before any kind of release (eg, I'm compiling Less and Coffeescript in-page) but the scrolling is my current concern, as it is central to my premise.
How can I best speed this up?