Advertisement
Boquete

Untitled

Jun 10th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function() {
  2.     function getClass(name) {
  3.         return document.getElementsByClassName(name)[0];
  4.     }
  5.  
  6.     /**
  7.      *
  8.      * @param element takes list or single class / id
  9.      * @param height takes list or single value with our without px's
  10.      */
  11.  
  12.     function changeHeight(element, height) {
  13.         function setHeight(element, height) {
  14.             if (height.toString().indexOf("px") > -1) {
  15.                 return getClass(element).style.height = height;
  16.             } else {
  17.                 return getClass(element).style.height = (height + 'px')
  18.             }
  19.         }
  20.  
  21.         if (Array.isArray(element) && Array.isArray(height)) {
  22.             for (i = 0; i < element.length; i++) {
  23.                 setHeight(element[i], height[i])
  24.             }
  25.         } else {
  26.             setHeight(element, height)
  27.         }
  28.     }
  29.  
  30.     /**
  31.      *
  32.      * @param elementOnScroll - scrolling this element will execute changing opacity
  33.      * @param elementOpacity - element or elements [list] of which opacity changes
  34.      * @param range - speed of changing opacity (e.g. 200)
  35.      * @param direction defines if elements increase or decrease their opacity when scrolling, takes one of two values ['inc', 'dec']
  36.      */
  37.     function changeOpacityOnScroll(elementOnScroll, elementOpacity, range, direction) {
  38.         elementOnScroll.onscroll = function() {
  39.             function setOpacity(elementOpacity) {
  40.                 if (direction == 'inc') {
  41.                     elementOpacity.style.opacity = (elementOnScroll.scrollTop / range);
  42.                 } else if (direction == 'dec') {
  43.                     elementOpacity.style.opacity = (1 - (elementOnScroll.scrollTop / range));
  44.  
  45.                 }
  46.             }
  47.  
  48.             if (Array.isArray(elementOpacity)) {
  49.                 for (i = 0; i < elementOpacity.length; i++) {
  50.                     setOpacity(elementOpacity[i])
  51.                 }
  52.             } else {
  53.                 setOpacity(elementOpacity)
  54.             }
  55.         };
  56.     }
  57.  
  58.     /**
  59.      *
  60.      * @param element takes element which parameters will change
  61.      * @param opacity takes numeric value or null
  62.      * @param visbility takes string value or null
  63.      * @param display takes string value or null
  64.      */
  65.     function displayElement(element, opacity, visbility, display) {
  66.         if (opacity) {
  67.             element.style.opacity = opacity;
  68.         }
  69.         if (visbility) {
  70.             element.style.visibility = visbility;
  71.         }
  72.         if (display) {
  73.             element.style.display = display
  74.         }
  75.     }
  76.  
  77.  
  78.     const projects = document.querySelectorAll('.piotrantosz, .cyfrowa, .lingsense, .megatruck, .taxi, .sugarizer');
  79.     const projectsHidden = getClass('projects__hidden');
  80.     const projectsCard = getClass('projects__cards');
  81.  
  82.     projects.forEach(function(entry) {
  83.         entry.addEventListener('click', function() {
  84.             const projectDescription = getClass(entry.getAttribute('class') + '__description');
  85.             displayElement(projectsHidden, 1, 'visible');
  86.             displayElement(projectDescription, 1, 'visible', 'block');
  87.             displayElement(projectsCard, 0, 'hidden,');
  88.             document.querySelectorAll('.title, .close').forEach(
  89.                 function(entry) {
  90.                     entry.addEventListener('click', function() {
  91.                         displayElement(projectDescription, null, null, 'none');
  92.                         displayElement(projectsHidden, 0, 'hidden');
  93.                         displayElement(projectsCard, 1)
  94.                     }, false);
  95.                 }
  96.             );
  97.         }, false);
  98.     });
  99.  
  100.     getClass('scroll').style.marginTop = 'calc(' + document.documentElement.clientHeight + 'px - 4em)';
  101.     changeOpacityOnScroll(getClass('content'), [getClass('scroll'), getClass('about__scroll')], 200, 'dec');
  102.     changeHeight(['wrapper', 'projects__hidden'], [document.documentElement.clientHeight, getClass('projects').offsetHeight]);
  103. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement