Browse code

Update

Benjamin Roth authored on17/03/2023 09:52:56
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,88 @@
1
+function changeAnchorLinks() {
2
+    var scrollPos = $(document).scrollTop();
3
+
4
+    if ($('#mainNav a[href*="#"]').length) {
5
+        $('#mainNav a[href*="#"]:not(.invisible)').each(function () {
6
+            var currElement = $(this);
7
+            var currLink = $(this).attr("href");
8
+            var refElement = currLink.substring(currLink.indexOf("#"));
9
+
10
+            if ($(refElement).position()) {
11
+                if (($(refElement).position().top - 500) <= scrollPos && ($(refElement).position().top - 500) + $(refElement).height() > scrollPos) {
12
+                    $("#mainNav .active").removeClass("active");
13
+                    currElement.addClass("active");
14
+                } else {
15
+                    //currElement.removeClass("active");
16
+                }
17
+            }
18
+        });
19
+    }
20
+
21
+    if ($(".onepagenavi--wrapper a").length) {
22
+        $(".onepagenavi--wrapper a").each(function () {
23
+            var currElement = $(this);
24
+            var currLink = $(this).attr("href");
25
+            var refElement = currLink.substring(currLink.indexOf("#"));
26
+
27
+            if ($(refElement).position()) {
28
+                if (($(refElement).position().top - 500) <= scrollPos && ($(refElement).position().top - 500) + $(refElement).height() > scrollPos) {
29
+                    $(".onepagenavi--wrapper .active").removeClass("active");
30
+                    currElement.addClass("active");
31
+                } else {
32
+                    //currElement.removeClass("active");
33
+                }
34
+            }
35
+        });
36
+    }
37
+}
38
+
39
+function changeNavLinksAfterLoad() {
40
+    $("#mobileNav li > *, #mainNav li > *, .onepagenavi--wrapper li > *").each(
41
+        function (index) {
42
+            var hash = window.location.hash;
43
+            if ($(this).attr("href") == hash) {
44
+                $("#mobileNav .active").removeClass("active");
45
+                $("#mobileNav .mm-listitem_selected").removeClass(
46
+                    "mm-listitem_selected"
47
+                );
48
+                $(this).addClass("active");
49
+                $(this).parent().addClass("mm-listitem_selected");
50
+            } else if ($(this).attr("href") == "#top") {
51
+                $("#mobileNav .level_1 > .first").addClass("listitem_selected");
52
+            }
53
+        }
54
+    );
55
+    changeAnchorLinks();
56
+}
57
+
58
+
59
+if ($(".scrollToTop, .BodyScrollToTop").length) {
60
+    $(".scrollToTop, .BodyScrollToTop").click(function () {
61
+        $("html,body").animate({scrollTop: $("#top").offset().top}, "500");
62
+        return false;
63
+    });
64
+    $(window).scroll(function () {
65
+        if ($(this).scrollTop() > 50) {
66
+            $(".BodyScrollToTop").addClass("visible");
67
+        } else {
68
+            $(".BodyScrollToTop").removeClass("visible");
69
+        }
70
+    });
71
+}
72
+
73
+
74
+/* Smooth Scrolling and set correct Item active */
75
+if (window.location.hash) {
76
+    var hash = window.location.hash;
77
+
78
+    if ($(hash).length) {
79
+        changeNavLinksAfterLoad();
80
+    }
81
+}
82
+
83
+
84
+changeAnchorLinks();
85
+
86
+$(document).on("scroll", function () {
87
+    changeAnchorLinks();
88
+});