Browse Source

made script compatible with IE8

T. Meissner 6 years ago
parent
commit
9d6ab0b339
1 changed files with 21 additions and 11 deletions
  1. 21
    11
      js/meissner-wohnen.js

+ 21
- 11
js/meissner-wohnen.js View File

@@ -1,18 +1,28 @@
1 1
 (function() {
2 2
 
3 3
 
4
-    var wohnung = document.getElementsByClassName("wohnung-img"),
5
-        kueche = document.getElementsByClassName("kueche-img"),
6
-        bad = document.getElementsByClassName("bad-img"),
4
+    var wohnung = document.querySelectorAll(".wohnung-img"),
5
+        kueche = document.querySelectorAll(".kueche-img"),
6
+        bad = document.querySelectorAll(".bad-img"),
7 7
         index = 0;
8 8
 
9 9
 
10
+    // add class 'active' to the element
10 11
     var setActive = function (element) {
11
-        document.getElementById(element).classList.add("active");
12
+        if(document.getElementById(element).classList) {
13
+            document.getElementById(element).classList.add("active");
14
+        } else {
15
+            document.getElementById(element).setAttribute("class", "active");
16
+        }
12 17
     };
13 18
 
19
+    // remove class 'active' from element
14 20
     var setDeactive = function (element) {
15
-        document.getElementById(element).classList.remove("active");
21
+        if(document.getElementById(element).classList) {
22
+            document.getElementById(element).classList.remove("active");
23
+        } else {
24
+            document.getElementById(element).removeAttribute("class");
25
+        }
16 26
     };
17 27
 
18 28
 
@@ -21,8 +31,8 @@
21 31
             wohnung[index].addEventListener("mouseenter", function(){setActive("wohnung")}, false);
22 32
             wohnung[index].addEventListener("mouseleave", function(){setDeactive("wohnung")}, false);
23 33
         } else {
24
-            wohnung.attachEvent("onmouseenter", function(){setActive("wohnung")});
25
-            wohnung.attachEvent("onmouseleave", function(){setDeactive("wohnung")});
34
+            wohnung[index].attachEvent("onmouseenter", function(){setActive("wohnung")});
35
+            wohnung[index].attachEvent("onmouseleave", function(){setDeactive("wohnung")});
26 36
         }
27 37
     }
28 38
     for (index=0; index <= kueche.length-1; index++) {
@@ -30,8 +40,8 @@
30 40
             kueche[index].addEventListener("mouseenter", function(){setActive("kueche")}, false);
31 41
             kueche[index].addEventListener("mouseleave", function(){setDeactive("kueche")}, false);
32 42
         } else {
33
-            kueche.attachEvent("onmouseenter", function(){setActive("kueche")});
34
-            kueche.attachEvent("onmouseleave", function(){setDeactive("kueche")});
43
+            kueche[index].attachEvent("onmouseenter",  function(){setActive("kueche")});
44
+            kueche[index].attachEvent("onmouseleave",  function(){setDeactive("kueche")});
35 45
         }
36 46
     }
37 47
     for (index=0; index <= bad.length-1; index++) {
@@ -39,8 +49,8 @@
39 49
             bad[index].addEventListener("mouseenter", function(){setActive("bad")}, false);
40 50
             bad[index].addEventListener("mouseleave", function(){setDeactive("bad")}, false);
41 51
         } else {
42
-            bad.attachEvent("onmouseenter", function(){setActive("bad")});
43
-            bad.attachEvent("onmouseleave", function(){setDeactive("bad")});
52
+            bad[index].attachEvent("onmouseenter", function(){setActive("bad")});
53
+            bad[index].attachEvent("onmouseleave", function(){setDeactive("bad")});
44 54
         }
45 55
     }
46 56