scrollDelegate woes


#1

I’m having trouble with the scroll delegate, (snippet below). When the user clicks the button to start scrolling, it works just fine, but the behavior is erradic when stopping and starting the scroll (here, by turning ‘scrolling’ from false to true then back). When the user stops scrolling (scrolling = false) the ion-scroll scrolls jumps back to the top–unless I uncomment the line in the else block to scroll by 0 px Y. Regardless of where the scrolling stops, when I re-initiate the scrolling, the ion-view jumps back to the top and restarts scrollings from the top.

I tried using the scrollDelegate to remember the position of each step, then whenever the user stops scrolling, it’d scroll to that last remembered step (a hackish attempt at a fix) but I’ve had no luck yet…

I’m realizing that I should probably just do this with jQuery (swallow my pride), but I’m really curious why my method isn’t working. Any advice?

this.startScroll = function () {

	scrolling = true 
	step = 3
	fr = 200 

	doScroll = function (){
		if(scrolling == true){
			scrollDelegate.scrollBy(0,step,true)
			scrollDelegate.rememberScrollPosition('pause')
			$timeout(doScroll, fr)
		} else {
			// scrollDelegate.scrollBy(0,0,false)	    		
			scrollDelegate.scrollToRememberedPosition('pause')
		}
	}
	doScroll()

	};
    	this.stopScroll = function(){
    		scrollDelegate.rememberScrollPosition('pause')
    		scrolling = false
    }

#2

Figured it out (I think!) my directive that was using this service the above snippet came from was updating the scope before the last $timeout from stopScroll() was being run–by the time that last time it was being run, my previous line was running a $digest to toggle the play/pause button and it was too late for the scrollTo/By in the else block to be run! ( I think–at least evidence seems to point that way). I changed stopScroll to defer returning a falsy value to my directive until after the last $timeout runs, and then no more reverting to the top issues!

Also changed $timeout to $interval because that clearly makes more sense here.