main.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. window.onload = function() {
  2. var req = new XMLHttpRequest();
  3. // first add raf shim
  4. // http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
  5. window.requestAnimFrame = (function(){
  6. return window.requestAnimationFrame ||
  7. window.webkitRequestAnimationFrame ||
  8. window.mozRequestAnimationFrame ||
  9. function( callback ){
  10. window.setTimeout(callback, 1000 / 60);
  11. };
  12. })();
  13. // main function
  14. function scrollToY(scrollTargetY, speed, easing) {
  15. // scrollTargetY: the target scrollY property of the window
  16. // speed: time in pixels per second
  17. // easing: easing equation to use
  18. var scrollY = window.scrollY,
  19. scrollTargetY = scrollTargetY || 0,
  20. speed = speed || 2000,
  21. easing = easing || 'easeOutSine',
  22. currentTime = 0;
  23. // min time .1, max time .8 seconds
  24. var time = Math.max(.1, Math.min(Math.abs(scrollY - scrollTargetY) / speed, .8));
  25. // easing equations from https://github.com/danro/easing-js/blob/master/easing.js
  26. var PI_D2 = Math.PI / 2,
  27. easingEquations = {
  28. easeOutSine: function (pos) {
  29. return Math.sin(pos * (Math.PI / 2));
  30. },
  31. easeInOutSine: function (pos) {
  32. return (-0.5 * (Math.cos(Math.PI * pos) - 1));
  33. },
  34. easeInOutQuint: function (pos) {
  35. if ((pos /= 0.5) < 1) {
  36. return 0.5 * Math.pow(pos, 5);
  37. }
  38. return 0.5 * (Math.pow((pos - 2), 5) + 2);
  39. }
  40. };
  41. // add animation loop
  42. function tick() {
  43. currentTime += 1 / 60;
  44. var p = currentTime / time;
  45. var t = easingEquations[easing](p);
  46. if (p < 1) {
  47. requestAnimFrame(tick);
  48. window.scrollTo(0, scrollY + ((scrollTargetY - scrollY) * t));
  49. } else {
  50. console.log('scroll done');
  51. window.scrollTo(0, scrollTargetY);
  52. }
  53. }
  54. // call it once to get started
  55. tick();
  56. }
  57. var availableWidth = [ 500, 1024, 1400, 1920];
  58. var size=0;
  59. var banner=document.getElementById("banner");
  60. while (window.innerWidth > availableWidth[size] && size < availableWidth.length-1 )
  61. size++;
  62. banner.src="Images/slider/slide1-"+availableWidth[size]+".jpg";
  63. var contact= document.getElementsByClassName("contact");
  64. var tit_curso = document.getElementsByClassName("titulo_curso");
  65. var desc_curso = document.getElementsByClassName("descripcion_curso");
  66. var list = document.getElementsByTagName("li");
  67. var overlay=document.getElementById('overlay-contact');
  68. var exit=document.getElementById('exit');
  69. var basicgrey=document.getElementById('basic-grey');
  70. var logo=document.getElementById('logo');
  71. var btnconsulta=document.getElementById('btnconsulta');
  72. var btnok=document.getElementById('ok');
  73. function curso_click(){
  74. for(var j =0; j < desc_curso.length; j++){
  75. if (desc_curso[j].getAttribute("tatosa") == this.getAttribute("tatosa"))
  76. desc_curso[j].style.display="block";
  77. }
  78. }
  79. overlay.onclick = function(){
  80. overlay.style.display="none";
  81. basicgrey.style.display="none";
  82. }
  83. exit.onclick=function(){
  84. overlay.style.display="none";
  85. basicgrey.style.display="none";
  86. }
  87. btnok.onclick=function(){
  88. var params="mail="+document.getElementById("suscribe").value;
  89. req.open("POST", "newsletter.php", true);
  90. req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  91. req.setRequestHeader("Content-length", params.length);
  92. req.setRequestHeader("Connection", "close");
  93. req.onreadystatechange=function(){
  94. if(req.readyState == 4 && req.status == 200)
  95. document.getElementById("respuestanewsletter").innerHTML=req.responseText;
  96. }
  97. req.send(params);
  98. };
  99. btnconsulta.onclick=function(){
  100. var params = "nombre="+document.getElementById("name").value;
  101. params=params+"&mail="+document.getElementById("email").value;
  102. params=params+"&consulta="+document.getElementById("message").value;
  103. req.open("POST", "contacto.php", true);
  104. req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  105. req.setRequestHeader("Content-length", params.length);
  106. req.setRequestHeader("Connection", "close");
  107. req.onreadystatechange=function(){
  108. if(req.readyState == 4 && req.status == 200)
  109. document.getElementById("respuestacontacto").innerHTML=req.responseText;
  110. }
  111. req.send(params);
  112. };
  113. for(var i =0; i < tit_curso.length; i++)
  114. tit_curso[i].onclick=curso_click;
  115. for(var i =0; i < contact.length; i++)
  116. contact[i].onclick=showContact;
  117. for(var i =0; i < list.length; i++)
  118. if(list[i].firstChild.tagName=="A")
  119. list[i].firstChild.addEventListener("click", function(e) {
  120. var target=document.getElementById(this.hash.replace("#",""))
  121. scrollToY(target.offsetTop, 1500, 'easeInOutQuint');
  122. if (this.hash=='#footer-outer')
  123. showContact();
  124. e.preventDefault();
  125. });
  126. function showContact() {
  127. basicgrey.style.display="block";
  128. overlay.style.display="block";
  129. }
  130. var startY=banner.scrollHeight;
  131. window.onscroll = function () {
  132. logo.style.opacity=1*(window.pageYOffset > startY ); //bool->int
  133. };
  134. var curImg=1;
  135. setInterval(slide, 8000);
  136. function slide() {
  137. banner.className='transp';
  138. setTimeout(transp, 500);
  139. curImg++;
  140. if(curImg>5) curImg=1;
  141. }
  142. function transp() {
  143. banner.src="Images/slider/slide"+curImg+"-"+availableWidth[size]+".jpg";
  144. banner.removeAttribute('class');
  145. }
  146. }