Explorar el Código

only check pdf page visibility on scroll every 50ms

Brian Gough hace 12 años
padre
commit
44057a9632

+ 18 - 6
services/web/public/coffee/ide/pdfng/directives/pdfViewer.coffee

@@ -258,16 +258,28 @@ define [
 					#scope.$apply()
 					#scope.$apply()
 
 
 				element.on 'scroll', () ->
 				element.on 'scroll', () ->
-					# console.log 'scroll detected', scope.adjustingScroll
-					updateContainer()
-					scope.$apply()
-					#console.log 'pdfposition', element.parent().scrollTop()
 					if scope.adjustingScroll
 					if scope.adjustingScroll
+						updateContainer()
+						scope.$apply()
 						scope.adjustingScroll = false
 						scope.adjustingScroll = false
 						return
 						return
-					#console.log 'not from auto scroll'
+					scope.scrolled = true
+					return if scope.handler?
+					scope.handler = requestAnimationFrame(scrollHandler)
+
+				scrollStart = null
+				SCROLL_TIMEOUT = 50
+				scrollHandler = (timestamp) ->
+					scrollStart = timestamp if !scrollStart?
+					progress = timestamp - scrollStart
+					if (progress < SCROLL_TIMEOUT)
+						scope.handler = requestAnimationFrame(scrollHandler)
+						return
+					scrollStart = null
+					scope.handler = null
+					updateContainer()
+					scope.$apply()
 					scope.position = ctrl.getPdfPosition()
 					scope.position = ctrl.getPdfPosition()
-					# console.log 'position is', scope.position.page, scope.position.offset
 					scope.$apply()
 					scope.$apply()
 
 
 				scope.$watch 'pdfSrc', (newVal, oldVal) ->
 				scope.$watch 'pdfSrc', (newVal, oldVal) ->