Advertisement
Guest User

Untitled

a guest
Jul 12th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. <!Doctype html>
  2.  
  3. <head>
  4.  
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8">
  6.  
  7. <style type="text/css">
  8. body {
  9. margin: 0;
  10. background-color: red;
  11. }
  12.  
  13.  
  14.  
  15. header{
  16. background-color:orange;
  17. height: 80px;
  18. }
  19.  
  20. #platzhalter{
  21. position: absolute;
  22. top: 150px;
  23. width: 1000px;
  24. height: 2000px;
  25. }
  26.  
  27. #navibereich li{
  28. display: inline; /* Listenelement nebeneinander */
  29. list-style-type: none; /* keine Aufzählungspunkte */
  30. }
  31.  
  32.  
  33. #navibereich{
  34. margin: 0;
  35. background-color:green; /* Hintergrundfarbe Navigationsbereich */
  36. padding: 10px 100px; /* oben/unten # px - re/li 0 */
  37. border-top: 3px solid white; /* Rahmen oben */
  38. border-bottom: 3px solid white; /* Rahmen unten */
  39. margin: 0px; /* Außenabstand */
  40. }
  41.  
  42.  
  43.  
  44.  
  45. #navibereich a{
  46. color: white; /* Schriftfarbe */
  47. text-decoration: none; /* Keine Unterstreichung */
  48. padding: 10px 8px; /* oben unten 4px; re/li 8px */
  49. }
  50.  
  51. #navibereich a:hover{ /* Farbveränderung, wenn Maus */
  52. background-color: blue;
  53. }
  54.  
  55.  
  56. #navigation.fixed{
  57. position:fixed;
  58. background-color: blue;
  59. top:0;
  60. height:40px;
  61. color:white;
  62. }
  63.  
  64.  
  65.  
  66. #navigation{
  67. position:absolute;
  68. background-color:blue;
  69. width: 100%;
  70. height: 40px;
  71. color:white;
  72. }
  73.  
  74.  
  75.  
  76. #hiddenObject {
  77. display:none
  78. }
  79.  
  80. #Farbe1{
  81. background-color:white;
  82. width: 100%;
  83. height: 100px;
  84. }
  85.  
  86. </style>
  87.  
  88. <script src="http://code.jquery.com/jquery-latest.js"></script>
  89. <script>
  90. $(document).on('click', '#handler', function(e) {
  91. e.preventDefault();
  92. if (!$(this).hasClass('active')) {
  93. $('#hiddenObject').show();
  94. } else {
  95. $('#hiddenObject').hide();
  96. }
  97.  
  98. $(this).toggleClass('active');
  99. });
  100. </script>
  101.  
  102. </head>
  103.  
  104.  
  105.  
  106. <body>
  107.  
  108. <header>
  109. Hallo! servas korli
  110. </header>
  111.  
  112.  
  113. <div id="body2">
  114.  
  115.  
  116.  
  117.  
  118. </div>
  119.  
  120. <div id="platzhalter">
  121.  
  122. </div>
  123.  
  124. <div id="navigation">
  125. <ul id = "navibereich">
  126. <li id="navi01"><a id="handler" href="http://google.com">Startseite</a></li>
  127. <li id="navi02"><a href="#">Kontakt</a></li>
  128. </ul>
  129.  
  130. <div id="hiddenObject">
  131. <div id="Farbe1">
  132. <a href="http://google.com">Servas</a>
  133. </div>
  134. </div>
  135. </div>
  136.  
  137.  
  138.  
  139.  
  140. <script type="text/javascript">
  141. var navi = document.getElementById("navigation");
  142. var naviPosY = navi.offsetTop;
  143.  
  144. document.addEventListener("scroll", function(e) {
  145. if (window.scrollY >= naviPosY){
  146. navi.className ="fixed";
  147.  
  148. } else {
  149. navi.className ="absolute";
  150. }
  151. });
  152.  
  153. </script>
  154.  
  155. </body>
  156.  
  157. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement