avia-compat.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. this prevents dom flickering for elements hidden with js, needs to be outside of dom.ready event.also adds several extra classes for better browser support
  3. this is a separate file that needs to be loaded at the top of the page. other js functions are loaded before the closing body tag to make the site render faster
  4. */
  5. "use strict"
  6. var avia_is_mobile = false;
  7. if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) && 'ontouchstart' in document.documentElement)
  8. {
  9. avia_is_mobile = true;
  10. document.documentElement.className += ' avia_mobile ';
  11. }
  12. else
  13. {
  14. document.documentElement.className += ' avia_desktop ';
  15. }
  16. document.documentElement.className += ' js_active ';
  17. (function(){
  18. //set transform property
  19. var prefix = ['-webkit-','-moz-', '-ms-', ""], transform = "";
  20. for (var i in prefix)
  21. {
  22. // http://artsy.github.io/blog/2012/10/18/so-you-want-to-do-a-css3-3d-transform/
  23. if(prefix[i]+'transform' in document.documentElement.style)
  24. { document.documentElement.className += " avia_transform "; transform = prefix[i]+'transform'}
  25. if(prefix[i]+'perspective' in document.documentElement.style) document.documentElement.className += " avia_transform3d ";
  26. }
  27. //set parallax position to prevent jump at pageload
  28. if(typeof document.getElementsByClassName == 'function' && typeof document.documentElement.getBoundingClientRect == "function" && avia_is_mobile == false)
  29. {
  30. if(transform && window.innerHeight > 0)
  31. {
  32. setTimeout(function(){
  33. var y = 0, offsets = {}, transY = 0, parallax = document.getElementsByClassName("av-parallax"),
  34. winTop = window.pageYOffset || document.documentElement.scrollTop;
  35. for (y = 0; y < parallax.length; y++) {
  36. parallax[y].style.top = "0px";
  37. offsets = parallax[y].getBoundingClientRect();
  38. transY = Math.ceil( (window.innerHeight + winTop - offsets.top) * 0.3 );
  39. parallax[y].style[transform] = "translate(0px, "+transY+"px)";
  40. parallax[y].style.top = "auto";
  41. parallax[y].className += ' enabled-parallax ';
  42. }
  43. }, 50);
  44. }
  45. }
  46. })();