Skip to content

Instantly share code, notes, and snippets.

@dbox
Created May 3, 2012 17:01
Show Gist options
  • Save dbox/2587257 to your computer and use it in GitHub Desktop.
Save dbox/2587257 to your computer and use it in GitHub Desktop.
iPhone position:fixed scroll fix
// Fixed position fix
$('nav ul a').click(function(){
// Find anchor position based on href
var y=Math.floor($($(this).attr('href')).offset().top);
// Add position fixed to nav
fixIt();
// Animate to anchor position
$('html,body').animate({ scrollTop:y},500,function(){
// On animation complete add position absolute to nav
// using the anchor position as top
$('nav ul, h1 a').css({position:'absolute',top:y})
})
// Prevent default
return false;
});
// Add position fixed on touch move
$(document).bind('touchmove',fixIt);
function fixIt(){$('nav ul, h1 a').css({position:'fixed',top:0})}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment