Просмотр исходного кода

Template: Enhance action bar scroll function.

Nate 5 лет назад
Родитель
Сommit
33f07a9540
1 измененных файлов с 15 добавлено и 5 удалено
  1. 15 5
      themes/default/template.php

+ 15 - 5
themes/default/template.php

@@ -378,11 +378,21 @@ echo "<script language='JavaScript' type='text/javascript' src='<!--{project_pat
 		}
 
 	//handle action bar style on scroll
-		window.addEventListener('scroll', action_bar_scroll , false);
-		function action_bar_scroll() {
-			if (document.getElementById('action_bar')) {
-				if (this.scrollY > 20) { document.getElementById('action_bar').classList.add('scroll'); }
-				if (this.scrollY < 20) { document.getElementById('action_bar').classList.remove('scroll'); }
+		window.addEventListener('scroll', function(){
+			action_bar_scroll('action_bar', 20);
+		}, false);
+		function action_bar_scroll(action_bar_id, scroll_position, function_sticky, function_inline) {
+			if (document.getElementById(action_bar_id)) {
+				//sticky
+					if (this.scrollY > scroll_position) {
+						document.getElementById(action_bar_id).classList.add('scroll');
+						if (typeof function_sticky === 'function') { function_sticky(); }
+					}
+				//inline
+					if (this.scrollY < scroll_position) {
+						document.getElementById(action_bar_id).classList.remove('scroll');
+						if (typeof function_inline === 'function') { function_inline(); }
+					}
 			}
 		}