Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.29 KB | None | 0 0
  1. (function () {
  2. 'use strict';
  3.  
  4. var box1 = document.getElementById("box1");
  5. var winHeight = window.innerHeight;
  6. var winWidth = window.innerWidth;
  7. var boxHeight = box1.offsetHeight;
  8. var boxWidth = box1.offsetWidth;
  9.  
  10. function printConsole() {
  11. console.log(winHeight);
  12. console.log(winWidth);
  13. console.log(boxHeight);
  14. console.log(boxWidth);
  15. console.log(window.getComputedStyle(box1).left);
  16. console.log(window.getComputedStyle(box1).top);
  17. }
  18.  
  19. function centerBox() {
  20. winHeight = window.innerHeight;
  21. winWidth = window.innerWidth;
  22. boxHeight = box1.offsetHeight;
  23. boxWidth = box1.offsetWidth;
  24.  
  25. box1.style.left = (winWidth / 2) - (boxWidth / 2) + "px";
  26. box1.style.top = (winHeight / 2) - (boxHeight / 2) + "px";
  27. }
  28.  
  29. function circle() {
  30. var all = document.getElementsByClassName("selected");
  31.  
  32. for (var i = 0; i < all.length; i++) {
  33. all[i].classList.toggle("circle");
  34. }
  35. }
  36.  
  37. function increaseSize() {
  38. var all = document.getElementsByClassName("selected");
  39.  
  40. for (var i = 0; i < all.length; i++) {
  41. winHeight = window.innerHeight;
  42. winWidth = window.innerWidth;
  43. boxHeight = all[i].offsetHeight;
  44. boxWidth = all[i].offsetWidth;
  45.  
  46. all[i].style.width = boxWidth + 5 + "px";
  47. all[i].style.height = boxHeight + 5 + "px";
  48. box1.style.left = (winWidth / 2) - (boxWidth / 2) + "px";
  49. box1.style.top = (winHeight / 2) - (boxHeight / 2) + "px";
  50. }
  51. }
  52.  
  53. function decreaseSize() {
  54. var all = document.getElementsByClassName("selected");
  55.  
  56. for (var i = 0; i < all.length; i++) {
  57. winHeight = window.innerHeight;
  58. winWidth = window.innerWidth;
  59. boxHeight = all[i].offsetHeight;
  60. boxWidth = all[i].offsetWidth;
  61.  
  62. all[i].style.width = boxWidth - 5 + "px";
  63. all[i].style.height = boxHeight - 5 + "px";
  64. box1.style.left = (winWidth / 2) - (boxWidth / 2) + "px";
  65. box1.style.top = (winHeight / 2) - (boxHeight / 2) + "px";
  66. }
  67. }
  68.  
  69. function switchColor() {
  70. var all = document.getElementsByClassName("selected");
  71.  
  72. for (var i = 0; i < all.length; i++) {
  73. var test1 = window.getComputedStyle(all[i]).getPropertyValue("background-color");
  74.  
  75. if (test1 == "rgb(0, 0, 255)") {
  76. all[i].style.backgroundColor = "rgb(0, 128, 0)";
  77. }
  78.  
  79. if (test1 == "rgb(255, 0, 0)") {
  80. all[i].style.backgroundColor = "rgb(0, 0, 255)";
  81. }
  82.  
  83. if (test1 == "rgb(255, 255, 0)") {
  84. all[i].style.backgroundColor = "rgb(255, 0, 0)";
  85. }
  86.  
  87. if (test1 == "rgb(0, 128, 0)") {
  88. all[i].style.backgroundColor = "rgb(255, 255, 0)";
  89. }
  90. }
  91. }
  92.  
  93. function cloneObj() {
  94. var all = document.querySelectorAll(".selected");
  95.  
  96. winHeight = window.innerHeight;
  97. winWidth = window.innerWidth;
  98.  
  99. for (var i = 0; i < all.length; i++) {
  100. var clone = all[i].cloneNode(true);
  101.  
  102. var funcTest = function clonePosition() {
  103. clone.style.position = 'absolute';
  104. clone.style.left = Math.round(Math.random() * winWidth) / 1.2 + 'px';
  105. clone.style.top = Math.round(Math.random() * winHeight) / 1.2 + 'px';
  106. clone.style.right = Math.round(Math.random() * winWidth) / 1.2 + 'px';
  107. clone.style.top = Math.round(Math.random() * winHeight) / 1.2 + 'px';
  108. };
  109.  
  110. window.addEventListener("resize", funcTest);
  111. clone.addEventListener("click", function(event) {
  112. event.target.classList.toggle("selected");
  113. });
  114.  
  115. clone.addEventListener("dblclick", function(event) {
  116. event.target.classList.toggle("animateSize");
  117.  
  118. setTimeout(function() {
  119. var all = document.querySelectorAll(".animateSize");
  120.  
  121. for (var i = 0; i < all.length; i++) {
  122. document.body.removeChild(all[i]);
  123. }
  124. }, 2000);
  125. });
  126.  
  127. funcTest();
  128.  
  129. document.body.appendChild(clone);
  130.  
  131. console.log("Antal Kloner = " + all.length);
  132. }
  133. }
  134.  
  135. function indexMinus() {
  136. var all = document.getElementsByClassName("selected");
  137.  
  138. for (var i = 0; i < all.length; i++) {
  139. var test1 = window.getComputedStyle(all[i]).getPropertyValue("z-index");
  140.  
  141. all[i].style.zIndex = test1 - 1;
  142. }
  143. }
  144.  
  145. function indexPlus() {
  146. var all = document.getElementsByClassName("selected");
  147.  
  148. for (var i = 0; i < all.length; i++) {
  149. var test2 = window.getComputedStyle(all[i]).getPropertyValue("z-index");
  150.  
  151. all[i].style.zIndex = parseInt(test2) + 1;
  152. }
  153. }
  154.  
  155. function removeObj() {
  156. var all = document.querySelectorAll(".selected");
  157.  
  158. for (var i = 0; i < all.length; i++) {
  159. document.body.removeChild(all[i]);
  160. }
  161. }
  162.  
  163. function arrowUp() {
  164. var all = document.getElementsByClassName("selected");
  165. var step = 10;
  166.  
  167. for (var i = 0; i < all.length; i++) {
  168. var top = all[i].offsetTop;
  169.  
  170. all[i].style.top = (top - step) + "px";
  171. }
  172. }
  173.  
  174. function arrowDown() {
  175. var all = document.getElementsByClassName("selected");
  176. var step = 10;
  177.  
  178. for (var i = 0; i < all.length; i++) {
  179. var top = all[i].offsetTop;
  180.  
  181. all[i].style.top = (top + step) + "px";
  182. }
  183. }
  184.  
  185. function arrowLeft() {
  186. var all = document.getElementsByClassName("selected");
  187. var step = 10;
  188.  
  189. for (var i = 0; i < all.length; i++) {
  190. var left = all[i].offsetLeft;
  191.  
  192. all[i].style.left = (left - step) + "px";
  193. }
  194. }
  195.  
  196. function arrowRight() {
  197. var all = document.getElementsByClassName("selected");
  198. var step = 10;
  199.  
  200. for (var i = 0; i < all.length; i++) {
  201. var left = all[i].offsetLeft;
  202.  
  203. all[i].style.left = (left + step) + "px";
  204. }
  205. }
  206.  
  207. function unTarget() {
  208. var els = document.getElementsByClassName("selected");
  209.  
  210. els[0].classList.remove("selected");
  211. if (els[0]) {
  212. unTarget();
  213. }
  214. }
  215.  
  216. function addClass() {
  217. var els = document.getElementsByClassName("box");
  218.  
  219. for (var i = 0; i < els.length; i++) {
  220. els[i].classList.add("selected");
  221. }
  222. console.log("Antal element med classen 'selected' = " + els.length);
  223. }
  224.  
  225. function slumpClone() {
  226. var all = document.querySelectorAll(".box");
  227.  
  228. winHeight = window.innerHeight;
  229. winWidth = window.innerWidth;
  230.  
  231. for (var i = 0; i < 1; i++) {
  232. var clone = all[i].cloneNode(true);
  233. var colors = ["rgb(0, 0, 255)", "rgb(0, 128, 0)", "rgb(255, 0, 0)", "rgb(255, 255, 0)"];
  234. var formType = ["0%", "50%"];
  235.  
  236. clone.classList.toggle("selected");
  237. clone.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)];
  238. clone.style.borderRadius = formType[Math.floor(Math.random() * colors.length)];
  239. clone.style.position = 'absolute';
  240. clone.style.left = Math.round(Math.random() * winWidth) / 1.2 + 'px';
  241. clone.style.top = Math.round(Math.random() * winHeight) / 1.2 + 'px';
  242. clone.style.right = Math.round(Math.random() * winWidth) / 1.2 + 'px';
  243. clone.style.top = Math.round(Math.random() * winHeight) / 1.2 + 'px';
  244.  
  245. clone.addEventListener("click", function(event) {
  246. event.target.classList.toggle("selected");
  247. });
  248.  
  249. clone.addEventListener("dblclick", function(event) {
  250. event.target.classList.toggle("animateSize");
  251.  
  252. setTimeout(function() {
  253. var all = document.querySelectorAll(".animateSize");
  254.  
  255. for (var i = 0; i < all.length; i++) {
  256. document.body.removeChild(all[i]);
  257. }
  258. }, 2000);
  259. });
  260.  
  261. document.body.appendChild(clone);
  262. }
  263. }
  264.  
  265. function christmas() {
  266. var els = document.getElementsByClassName("box");
  267.  
  268. for (var i = 0; i < els.length; i++) {
  269. els[i].classList.add("animateSize");
  270. }
  271.  
  272. setTimeout(function() {
  273. var all = document.querySelectorAll(".box");
  274.  
  275. for (var i = 0; i < all.length; i++) {
  276. document.body.removeChild(all[i]);
  277. }
  278. }, 1500);
  279.  
  280. setTimeout(function() {
  281. var all = document.querySelectorAll(".tomte1");
  282. var all1 = document.querySelectorAll(".tomte2");
  283. var all2 = document.querySelectorAll(".tomte3");
  284. var all3 = document.querySelectorAll(".tomte4");
  285. var all4 = document.querySelectorAll(".tomte5");
  286. var all5 = document.querySelectorAll(".tomte6");
  287. var all6 = document.querySelectorAll(".tomte7");
  288. var all7 = document.querySelectorAll(".tomte8");
  289. var all8 = document.querySelectorAll(".tomte9");
  290. var all9 = document.querySelectorAll(".tomte10");
  291. var all10 = document.querySelectorAll(".tomte11");
  292. var tag = document.getElementsByTagName("body");
  293.  
  294. for (var i = 0; i < tag.length; i++) {
  295. tag[i].style.backgroundColor = "#2c4051";
  296. }
  297.  
  298. for (i = 0; i < all.length; i++) {
  299. all[i].classList.add("santa");
  300. }
  301.  
  302. for (i = 0; i < all1.length; i++) {
  303. all1[i].classList.add("circles");
  304. }
  305.  
  306. for (i = 0; i < all2.length; i++) {
  307. all2[i].classList.add("snow");
  308. }
  309.  
  310. for (i = 0; i < all3.length; i++) {
  311. all3[i].classList.add("hat");
  312. }
  313.  
  314. for (i = 0; i < all4.length; i++) {
  315. all4[i].classList.add("hat-end");
  316. }
  317.  
  318. for (i = 0; i < all5.length; i++) {
  319. all5[i].classList.add("face");
  320. }
  321.  
  322. for (i = 0; i < all6.length; i++) {
  323. all6[i].classList.add("eyes");
  324. }
  325.  
  326. for (i = 0; i < all7.length; i++) {
  327. all7[i].classList.add("mouth");
  328. }
  329.  
  330. for (i = 0; i < all8.length; i++) {
  331. all8[i].classList.add("dirty-overflow");
  332. }
  333.  
  334. for (i = 0; i < all9.length; i++) {
  335. all9[i].classList.add("body");
  336. }
  337.  
  338. for (i = 0; i < all10.length; i++) {
  339. all10[i].classList.add("godjul", "godjul2");
  340. }
  341. }, 1500);
  342. }
  343.  
  344.  
  345.  
  346. function goCrazy() {
  347. var i = setInterval(function test40() {
  348. var all = document.querySelectorAll(".selected");
  349.  
  350. for (var i = 0; i < all.length; i++) {
  351. var colors = ["rgb(0, 0, 255)", "rgb(0, 128, 0)", "rgb(255, 0, 0)",
  352. "rgb(255, 255, 0)"];
  353. var formType = ["0%", "50%"];
  354.  
  355. winHeight = window.innerHeight;
  356. winWidth = window.innerWidth;
  357.  
  358. all[i].style.backgroundColor = colors[Math.floor(Math.random() * colors.length)];
  359. all[i].style.borderRadius = formType[Math.floor(Math.random() * colors.length)];
  360. all[i].style.left = Math.round(Math.random() * winWidth) / 1.2 + 'px';
  361. all[i].style.top = Math.round(Math.random() * winHeight) / 1.2 + 'px';
  362. all[i].style.right = Math.round(Math.random() * winWidth) / 1.2 + 'px';
  363. }
  364. }, 199);
  365.  
  366. setTimeout(function( ) { clearInterval( i ); }, 1000);
  367. }
  368.  
  369. window.addEventListener("resize", centerBox);
  370. box1.addEventListener("click", function(event) {
  371. event.target.classList.toggle("selected");
  372. });
  373.  
  374. box1.addEventListener("dblclick", function(event) {
  375. event.target.classList.toggle("animateSize");
  376.  
  377. setTimeout(function() {
  378. var all = document.querySelectorAll(".animateSize");
  379.  
  380. for (var i = 0; i < all.length; i++) {
  381. document.body.removeChild(all[i]);
  382. }
  383. }, 2000);
  384. });
  385.  
  386. document.addEventListener("keydown", function(event) {
  387. var key = event.key;
  388.  
  389. switch (key) {
  390. case "e":
  391. circle();
  392. break;
  393. case "q":
  394. increaseSize();
  395. break;
  396. case "w":
  397. decreaseSize();
  398. break;
  399. case "r":
  400. switchColor();
  401. break;
  402. case "t":
  403. cloneObj();
  404. break;
  405. case "a":
  406. indexMinus();
  407. break;
  408. case "s":
  409. indexPlus();
  410. break;
  411. case "y":
  412. removeObj();
  413. break;
  414. case "ArrowUp":
  415. event.preventDefault();
  416. arrowUp();
  417. break;
  418. case "ArrowDown":
  419. event.preventDefault();
  420. arrowDown();
  421. break;
  422. case "ArrowLeft":
  423. event.preventDefault();
  424. arrowLeft();
  425. break;
  426. case "ArrowRight":
  427. event.preventDefault();
  428. arrowRight();
  429. break;
  430. case "u":
  431. unTarget();
  432. break;
  433. case "i":
  434. addClass();
  435. break;
  436. case "p":
  437. slumpClone();
  438. break;
  439. case "d":
  440. goCrazy();
  441. break;
  442. case "1":
  443. christmas();
  444. break;
  445. }
  446. });
  447.  
  448. printConsole();
  449. centerBox();
  450.  
  451. console.log('Kmom05 Done!');
  452. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement