-
-
Save sarim/8045531 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Code to keep div fixed at top during scrolling. heavily inspired from http://goo.gl/zYykrQ | |
var scroller = { | |
touchstart: function(e) { | |
e.data.state.posY = e.touches[0].clientY; | |
e.data.state.offsetY = $('#indicator').offset().top; | |
$("#status").html("touchstart"); | |
}, | |
touchmove: function(e) { | |
var currentY = e.touches[0].clientY; | |
var deltaY = currentY - e.data.state.posY; | |
var newY = deltaY + e.data.state.offsetY; | |
$("#status").html("new pos: " + newY); | |
$('#indicator').offset({top: newY , left:0}); | |
}, | |
touchend: function(e) { | |
$("#status").html("touchend"); | |
}, | |
scroll: function(e) { | |
$("#status").html("scroll finished"); | |
$('#indicator').offset({top: $(window).scrollTop() , left:0}); | |
}, | |
state: {posY: 0, offsetY: 0} | |
} | |
$(function(){ | |
if (1 || "TODO: Detect Mobile") { | |
$(window).on('touchstart',scroller,scroller.touchstart); | |
$(window).on('touchmove',scroller,scroller.touchmove); | |
$(window).on('touchend',scroller,scroller.touchend); | |
$(window).on('scroll',scroller,scroller.scroll); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment