Advertisement
maximus87

Untitled

May 27th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 9.48 KB | None | 0 0
  1. <!-- Html part goes here -->
  2.  
  3. <section class="calculator">
  4.             <div class="calculator__wrapper">
  5.                 <h1 class="calculator__header">TITLE HERE</h1>
  6.                 <div id="employeesSlider" class="calculator__slider">
  7.                    <!-- Managed by js -->
  8.                 <div class="calculator__lower-fill"></div></div>
  9.                 <div class="calculator__stats">
  10.                     <div class="calculator__stat">
  11.                         <h2 class="big-title big-title--calculator" id="stat-colleagues"></h2>
  12.                         <p>colleagues are currently struggling with some form of mental health issue.</p>
  13.                     </div>
  14.                     <div class="calculator__stat">
  15.                         <h2 class="big-title big-title--calculator" id="stat-days"></h2>
  16.                         <p>days lost per year due to work-related stress, depression and anxiety.</p>
  17.                     </div>
  18.                     <div class="calculator__stat">
  19.                         <h2 class="big-title big-title--calculator"><span>£</span><span id="stat-cost"></span></h2>
  20.                         <p>the annual cost of ill-mental health across absenteeism, presenteeism, and staff turnover.</p>
  21.                     </div>
  22.                 </div>
  23.                 <div class="calculator__footer">
  24.                     <p>figures are estimated and based<br> on UK research</p>
  25.                 </div>
  26.             </div>
  27.         </section>
  28.  
  29. <!-- CSS part -->
  30.  
  31. <style type="text/css">
  32.   html,
  33.   body {
  34.     padding: 0;
  35.     margin: 0;
  36.     background: #fff;
  37.     font-family: 'Lato';
  38.   }
  39.   textarea {
  40.     resize: none;
  41.   }
  42.  
  43.   .slider-2 {
  44.     -webkit-touch-callout: none;
  45.     -webkit-user-select: none;
  46.     -khtml-user-select: none;
  47.     -moz-user-select: none;
  48.     -ms-user-select: none;
  49.     user-select: none;
  50.   }
  51.  
  52.   .calculator {
  53.     width: 100%;
  54.     clear: both;
  55.     background: #fff;
  56.     color: #3f3f3f;
  57.     overflow-x: hidden;
  58.   }
  59.  
  60.   .calculator__wrapper {
  61.     max-width: 1100px;
  62.     width: 96%;
  63.     margin: 0 auto;
  64.     padding: 40px 0;
  65.   }
  66.  
  67.   .calculator__header {
  68.     font-size: 36px;
  69.     font-weight: 500;
  70.     margin-top: 0;
  71.     margin-bottom: 150px;
  72.     font-family: 'CircularStd', 'Lato', sans-serif;
  73.     color: #373737;
  74.   }
  75.  
  76.   .calculator__slider {
  77.     position: relative;
  78.     width: 100%;
  79.     height: 8px;
  80.     background: #f7f7f7;
  81.     border: 1px solid #e5e5e5;
  82.     border-radius: 4px;
  83.     cursor: pointer;
  84.   }
  85.  
  86.   .calculator__slider > button {
  87.     border: 1px solid #000;
  88.     height: 38px;
  89.     border-radius: 19px;
  90.     background-color: #373737;
  91.     background-image: url('https://assets.website-files.com/5af2f6c042cd7abaee458b4e/5b584fefe017c37a58b357eb_calculator_handle.png');
  92.     background-size: 50%;
  93.     background-repeat: no-repeat;
  94.     background-position: center;
  95.     box-shadow: 0 0 0 2px #fff;
  96.     cursor: pointer;
  97.     width: 73px;
  98.     position: relative;
  99.     top: -15px;
  100.     z-index: +1;
  101.   }
  102.  
  103.   .calculator__slider > button,
  104.   .calculator__slider > button:active,
  105.   .calculator__slider > button:hover {
  106.     outline: 0;
  107.   }
  108.  
  109.   .calculator__slider output {
  110.     color: #3f3f3f;
  111.     position: absolute;
  112.     top: -72px;
  113.     font-size: 36px;
  114.     font-weight: bold;
  115.     cursor: pointer;
  116.     left: 50%;
  117.     -webkit-transform: translateX(-50%);
  118.     transform: translateX(-50%);
  119.   }
  120.  
  121.   .calculator__slider output:after {
  122.     content: '';
  123.     position: absolute;
  124.     bottom: -26px;
  125.     left: 0;
  126.     width: 36px;
  127.     height: 5px;
  128.     border-radius: 2.5px;
  129.     background: #e5e5e5;
  130.     left: 50%;
  131.     -webkit-transform: translateX(-50%);
  132.     transform: translateX(-50%);
  133.   }
  134.  
  135.   .calculator__lower-fill {
  136.     display: block;
  137.     height: 10px;
  138.     border-top-left-radius: 5px;
  139.     border-bottom-left-radius: 5px;
  140.     background: #ff4848;
  141.     position: absolute;
  142.     top: -1px;
  143.     left: -1px;
  144.     z-index: 0;
  145.   }
  146.  
  147.   .calculator__stats {
  148.     display: flex;
  149.     flex-direction: column;
  150.     margin-top: 64px;
  151.   }
  152.  
  153.   .calculator__stat {
  154.     width: 100%;
  155.     max-width: 33.33%;
  156.     padding-right: 16px;
  157.   }
  158.  
  159.   .calculator__stat:last-of-type {
  160.     margin-right: 0;
  161.   }
  162.  
  163.   .calculator__stat p {
  164.     font-size: 21px;
  165.     font-family: 'CircularStd', 'Lato', sans-serif;
  166.     line-height: 30px;
  167.     color: #373737;
  168.     margin-top: 0;
  169.   }
  170.  
  171.   .big-title {
  172.     font-size: 48px;
  173.     text-transform: uppercase;
  174.     font-family: 'CircularStd', 'Lato', sans-serif;
  175.     margin-bottom: 7px;
  176.     color: #ff4848;
  177.     font-weight: 400;
  178.     line-height: 1;
  179.   }
  180.  
  181.   .big-title--calculator {
  182.     color: #ff4848;
  183.   }
  184.  
  185.   .calculator__footer p {
  186.     color: #9f9f9f;
  187.     font-size: 14px;
  188.     letter-spacing: 0.42px;
  189.   }
  190.  
  191.   .calculator__footer p {
  192.     text-align: center;
  193.     display: flex;
  194.     font-family: 'CircularStd', 'Lato', sans-serif;
  195.     line-height: 18px;
  196.     margin-top: 30px;
  197.     line-height: 20px;
  198.     justify-content: center;
  199.   }
  200.  
  201.   .calculator__footer p:before {
  202.     content: '*';
  203.     display: block;
  204.     margin-right: 1px;
  205.   }
  206.  
  207.   #wf-form-Contact-Unmind .error {
  208.     color: #e61030;
  209.     position: absolute;
  210.     right: 25px;
  211.     top: 14px;
  212.     font-size: 14px;
  213.   }
  214.  
  215.   @media only screen and (min-width: 768px) {
  216.     .calculator__stats {
  217.       flex-direction: row;
  218.       justify-content: space-between;
  219.     }
  220.   }
  221. </style>
  222.  
  223. <!-- javascript part -->
  224.  
  225. <script type="text/javascript">
  226.   (function() {
  227.     document.addEventListener('DOMContentLoaded', function() {
  228.       var slider = document.getElementById('employeesSlider');
  229.  
  230.       var handle = document.createElement('BUTTON');
  231.       slider.appendChild(handle);
  232.  
  233.       var output = document.createElement('OUTPUT');
  234.       output.setAttribute('id', 'employeesValue');
  235.       handle.appendChild(output);
  236.  
  237.       var lowerFill = document.createElement('DIV');
  238.       lowerFill.setAttribute('class', 'calculator__lower-fill');
  239.       slider.appendChild(lowerFill);
  240.  
  241.       var sliderIsMoving = false;
  242.       var onSliderMove = function(e) {
  243.         if (sliderIsMoving) {
  244.           var min = 0,
  245.             max = slider.offsetWidth - handle.offsetWidth,
  246.             mousePos = e.pageX - slider.offsetLeft - handle.offsetWidth / 2,
  247.             position = mousePos > max ? max : mousePos < min ? min : mousePos,
  248.            value = (position / max) * 100;
  249.  
  250.          if (value < 1) value = 1;
  251.  
  252.          updateSlider(value, position);
  253.        }
  254.      };
  255.  
  256.      var updateSlider = function(value, position) {
  257.        handle.style.marginLeft = position + 'px';
  258.        lowerFill.style.width = value + '%';
  259.  
  260.        updateStats(value);
  261.      };
  262.  
  263.      function roundNumber(obj) {
  264.        return Object.entries(obj).reduce((result, [key, value]) => {
  265.           result[key] = Math.round(value);
  266.           return result;
  267.         }, {});
  268.       }
  269.  
  270.       function localeString(obj) {
  271.         return Object.entries(obj).reduce((result, [key, value]) => {
  272.           result[key] = value.toLocaleString('en-US', {
  273.             minimumFractionDigits: 0
  274.           });
  275.           return result;
  276.         }, {});
  277.       }
  278.  
  279.       const currentlyStruggling = numberOfEmployees =>
  280.         numberOfEmployees * 0.1667;
  281.       const experiencedAProblem = numberOfEmployees =>
  282.         numberOfEmployees * 0.414;
  283.       const daysLost = numberOfEmployees =>
  284.         currentlyStruggling(numberOfEmployees) * 25.8;
  285.       const costOfIllMentalHealth = numberOfEmployees =>
  286.         numberOfEmployees * 1300;
  287.  
  288.       function mentalHealthImpact(numberOfEmployees) {
  289.         const healthImpact = {
  290.           numberOfEmployees: numberOfEmployees,
  291.           currentlyStruggling: currentlyStruggling(numberOfEmployees),
  292.           experiencedAProblem: experiencedAProblem(numberOfEmployees),
  293.           daysLost: daysLost(numberOfEmployees),
  294.           costOfIllMentalHealth: costOfIllMentalHealth(numberOfEmployees)
  295.         };
  296.  
  297.         return localeString(roundNumber(healthImpact));
  298.       }
  299.  
  300.       function totalEmployees(value) {
  301.         const minv = Math.log(10);
  302.         const maxv = Math.log(100000);
  303.  
  304.         const scale = (maxv - minv) / 99;
  305.         return Math.round(Math.exp(minv + scale * (value - 1)));
  306.       }
  307.  
  308.       var updateStats = function(sliderPercentage) {
  309.         const numberOfEmployees = totalEmployees(sliderPercentage);
  310.         const stats = mentalHealthImpact(numberOfEmployees);
  311.  
  312.         document.getElementById('employeesValue').innerHTML =
  313.           stats.numberOfEmployees;
  314.         document.getElementById('stat-colleagues').innerHTML =
  315.           stats.currentlyStruggling;
  316.         document.getElementById('stat-days').innerHTML = stats.daysLost;
  317.         document.getElementById('stat-cost').innerHTML =
  318.           stats.costOfIllMentalHealth;
  319.       };
  320.  
  321.       var onMoveStart = function(e) {
  322.         sliderIsMoving = true;
  323.         onSliderMove(e);
  324.       };
  325.       var onMoveEnd = function(e) {
  326.         sliderIsMoving = false;
  327.       };
  328.  
  329.       slider.addEventListener('mousedown', onMoveStart);
  330.       slider.addEventListener('touchstart', onMoveStart);
  331.       document.addEventListener('mouseup', onMoveEnd);
  332.       document.addEventListener('touchend', onMoveEnd);
  333.       document.addEventListener('mousemove', function(e) {
  334.         onSliderMove(e);
  335.       });
  336.       document.addEventListener('touchmove', function(e) {
  337.         e.preventDefault();
  338.  
  339.         onSliderMove(e.touches[0]);
  340.       });
  341.  
  342.       updateSlider(
  343.         50.5,
  344.         slider.offsetWidth * 0.505 - handle.offsetWidth * 0.505
  345.       );
  346.     });
  347.   })();
  348. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement