lorro

Virtue Premium - Scroll summary block

Mar 21st, 2016
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // version: 22/03/16 13:10 GMT
  2.  
  3. window.onload = function() {
  4.   var w, h1, h2, h3, h4, elements, summary, hmax, smax;
  5.   w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
  6.   if (w < 768) {
  7.      return;
  8.   }
  9.   function getHeight(class_name) {
  10.     var elements = document.getElementsByClassName(class_name);
  11.     if (elements.length) {
  12.       return elements[0].scrollHeight;
  13.     } else {
  14.       return 0;
  15.     }
  16.   }
  17.   function setSummaryTop() {
  18.     h2 = getHeight("woocommerce-tabs");
  19.     h4 = summary.scrollHeight;
  20.     hmax = Math.max(h1 + h2 + h3 - h4, 0);
  21.     smax  = Math.max(window.scrollY - 220, 0);
  22.     summary.style.top = Math.min(hmax, smax) + "px";
  23.   }
  24.   elements = document.getElementsByClassName("product-summary-case");
  25.   if (elements.length) {
  26.     summary = elements[0];
  27.     h1 = getHeight("product-img-case");
  28.     h3 = getHeight("upsells");
  29.     window.onscroll = function() {
  30.       setSummaryTop();  
  31.     };
  32.     setInterval(setSummaryTop, 500);
  33.   }
  34. };
Add Comment
Please, Sign In to add comment