Skip to content

Instantly share code, notes, and snippets.

@XayOn
Created October 30, 2012 22:38
Show Gist options
  • Save XayOn/3983568 to your computer and use it in GitHub Desktop.
Save XayOn/3983568 to your computer and use it in GitHub Desktop.
Automagically scroll down an image when you scroll to its half.
($ document).ready ->
(($ document) .find '.showoff') .live 'mouseover', () ->
h = (($ this).css 'height').replace 'px', ''
($ document) .data 'next_position', ($ this).position().top + h + 20
($ document) .data 'launch_position', ($ this).position().top + (h / 2)
($ document).live 'scroll', (event) ->
if ((Number) ($ document).scrollTop() > ((Number) (($ document) .data 'launch_position'))
window.scrollTo(0, ($ document).data 'next_position')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment