I have this function I am running in a UIWebView. It works in Android as window.onscroll = scrollFunc; .. with ios I am doing document.ontouchend = scrollFunc; not sure if this is the right method. (I don't think it is, considering I also need to add an onclick method).
The other problem I am having is that ONLY the scroll up action is being called even though the diffY number comes back as negative when scrolling down and positive when scrolling up. I can't figure out why.
var prevDate = Date.now(); var curDate = prevDate;
function scrollFunc(e) {
curDate = Date.now();
if((curDate - prevDate) > 1000){
if ( typeof scrollFunc.y == 'undefined' ) {
scrollFunc.y=window.pageYOffset;
}
var diffY=scrollFunc.y-window.pageYOffset;
if( diffY<-3 ) {
// Scroll down action here
} else if( diffY>5 ) {
// Scroll up action here
} else {
// First scroll event
}
scrollFunc.y=window.pageYOffset;
prevDate = curDate;
}
}
Aucun commentaire:
Enregistrer un commentaire