Guest User

Untitled

a guest
Sep 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. <div id="leftbox">
  2. <p id="leftpopis"> Whats new on the web? </p>
  3. <img src="obrazky/0.png" id="imgDemo" >
  4. <button onclick="prvs()" id="btnTwo"> <img src="obrazky/left.png"/>
  5. </button>
  6. <button onclick="nxt()" id="btnOne"> <img src="obrazky/right.png"/>
  7. </button>
  8.  
  9. <script>
  10. var img = new
  11. Array("obrazky/0.png","obrazky/1.png","obrazky/2.png","obrazky/3.png");
  12.  
  13. var imgElement = document.getElementById("imgDemo");
  14. var i = 0;
  15. var imgLen = img.length;
  16.  
  17. function nxt()
  18. {
  19. if(i < imgLen-1)
  20. {
  21. i++;
  22. }
  23. else{
  24. i=0;
  25. }
  26.  
  27. imgElement.src = img[i];
  28. }
  29.  
  30. function prvs()
  31. {
  32. if(i > 0)
  33. {
  34. i--;
  35. }
  36. else
  37. {
  38. i = imgLen-1;
  39. }
  40. imgElement.src = img[i];
  41. }
  42.  
  43. var img = new Array Array("<a href="comments.html"> obrazky/0.png"</a>);
  44.  
  45. var img = new Array("<a href="comments.html"> obrazky/0.png"</a>);
  46.  
  47. var img = new Array("<a href='comments.html'> obrazky/0.png</a>");
  48.  
  49. var img = new Array(`<a href="comments.html"> obrazky/0.png</a>`);
  50.  
  51. [{img: "obrazky/0.png", url: "comments.html"}, {...}, {...}]
  52.  
  53. imgElement.src = img[i.img];
  54. linkElement.href = img[i.url];
  55.  
  56. var img = [ {link='xxx', src="obrazky/0.png"}, {link='yyy' src="obrazky/1.png"},... ]
  57.  
  58. <a id='imgDemoLink'> <img id='imgDemo'></a>
  59.  
  60. imgElement.src = img[i.src];
  61.  
  62. var aElement = document.getElementById("imgDemoLink");
  63. aElement.href = img[i.link]
  64.  
  65. var img = [
  66. {
  67. "img": "obrazky/0.png",
  68. "href": "comments.html",
  69. },
  70. {
  71. "img": "obrazky/0.png",
  72. "href": "comments.html",
  73. }
  74. ];
  75.  
  76. <a href="" id="imageAnchor"><img id="imgDemo" src=""></a>
  77.  
  78. document.getElementById("imageAnchor").href = img[i].href;
  79. document.getElementById("imgDemo").src = img[i].img;
  80.  
  81. <ul id="images">
  82. <li class='active'><a href="comments.html"><img src="obrazky/2.png"></a></li>
  83. <li><a href="comments.html"><img src="obrazky/1.png"></a></li>
  84. <li><a href="comments.html"><img src="obrazky/0.png"></a></li>
  85. </ul>
  86.  
  87. <style>
  88. ul#images {
  89. margin:0px;
  90. padding:0px;
  91. list-style-type:none;
  92. }
  93. ul#images li {
  94. display:none;
  95. }
  96. ul#images li:first-child,
  97. ul#images li.active {
  98. display:block;
  99. }
  100. </style>
  101.  
  102. <script>
  103. imageContainer = document.getElementById("images");
  104.  
  105. document.getElementById("btnOne").addEventListener(function(event) {
  106. event.preventDefault();
  107. //do magic here.
  108. //been a while since I've touched vanilla so give me a minute :d
  109. //basically what you need to do here is cycle through the nodes,
  110. //find the active one, if there is a nextSibling of .active:
  111. // set nextSibling.class ='active' and the current element remove active
  112. for(var i=0; i < imageContainer.childNodes.length; i++) {
  113. if (imageContainer.childNodes[i].className == 'active') {
  114. if (imageContainer.childNodes[i].nextSibling !== 'undefined') {
  115. imageContainer.childNodes[i].nextSibling.className = 'active';
  116. imageContainer.childNodes[i].className = '';
  117. }
  118. }
  119. }
  120. };
  121.  
  122. //Notice this function is similar and I've replaced nextSibling with Previous for the opposite direction
  123.  
  124. document.getElementById("btnTwo").addEventListener(function(event) {
  125. event.preventDefault();
  126.  
  127. for(var i=0; i < imageContainer.childNodes.length; i++) {
  128. if (imageContainer.childNodes[i].className == 'active') {
  129. if (imageContainer.childNodes[i].previousSibling !== 'undefined') {
  130. imageContainer.childNodes[i].previousSibling.className = 'active';
  131. imageContainer.childNodes[i].className = '';
  132. }
  133. }
  134. }
  135.  
  136. </script>
  137.  
  138. <script>
  139. var img = new Array("obrazky/0.png", "obrazky/1.png", "obrazky/2.png", "obrazky/3.png");
  140. //add this array for urls
  141. var urls = new Array("example1.com", "example2.com", "example3.com", "example4.com");
  142.  
  143. var imgElement = document.getElementById("imgDemo");
  144. var i = 0;
  145. var imgLen = img.length;
  146.  
  147. function nxt()
  148. {
  149. if(i < imgLen-1)
  150. {
  151. i++;
  152. }
  153. else{
  154. i=0;
  155. }
  156.  
  157. imgElement.src = img[i];
  158. //add click event to redirect
  159. document.getElementById("imgDemo").addEventListener("click", function(){
  160. window.location.href = urls[i];
  161. });
  162. }
  163.  
  164. function prvs()
  165. {
  166. if(i > 0)
  167. {
  168. i--;
  169. }
  170. else
  171. {
  172. i = imgLen-1;
  173. }
  174. imgElement.src = img[i];
  175. //add click event to redirect
  176. document.getElementById("imgDemo").addEventListener("click", function(){
  177. window.location.href = urls[i];
  178. });
  179. }
  180. </script>
Add Comment
Please, Sign In to add comment