Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.16 KB | None | 0 0
  1. ///////////////////////////////
  2. // See Your Folks calculation
  3. ///////////////////////////////
  4.  
  5.  
  6. function submit(){
  7.  
  8. var sel = document.getElementById("Example");
  9. console.log(sel);
  10.  
  11. var country = sel.options[sel.selectedIndex].value;
  12.  
  13. var querido = (Number(queridoAge.value));
  14. console.log("el valor de la variable 'querido' es: " + querido);
  15.  
  16. var tu = (Number(tuAge.value));
  17. console.log("el valor de la variable 'tu' es: " + tu);
  18.  
  19. var time = (Number(userTime.value));
  20.  
  21. var maxEdad =0;
  22. if (querido>tu) {
  23. maxEdad = querido;
  24. }
  25. else {
  26. maxEdad = tu;
  27. }
  28. var result = ((country-maxEdad)*time);
  29. result = Math.round(result * 10) / 10;
  30.  
  31.  
  32. var yearsOver = (maxEdad-country);
  33. var queridoOver = (querido-country);
  34. var tuOver = (tu-country);
  35.  
  36. var queridoResult = ((country-querido)*time);
  37. var tuResult = ((country-tu)*time);
  38.  
  39. // maxEdad Result
  40. if (result > 0){
  41. document.getElementById("demo").innerHTML= "Verás a tu ser querido</br>" + " <span>" + result + "</span></br> " + "veces antes de que muera.";
  42. }
  43. else {
  44. document.getElementById("demo").innerHTML= "Tu ser querido ha vivido</br>" + " <span>" + yearsOver + "</span></br> " + "años más que la media. ¡Aprovecha cada minuto!";
  45. }
  46.  
  47.  
  48. // Alternative Results
  49. // if(document.getElementById("tuAge").value == ""){
  50. // document.getElementById("demo").innerHTML= "You will see your Mum</br>" + " <span>" + queridoResult + "</span></br> " + "times before she is expected to die.";
  51. // }
  52. // if(document.getElementById("tuAge").value == "" & (querido > country)){
  53. // document.getElementById("demo").innerHTML= "Your mum is living</br>" + " <span>" + queridoOver + "</span></br> " + "years beyond the age she is expected to die.";
  54. // }
  55. // if(document.getElementById("queridoAge").value == ""){
  56. // document.getElementById("demo").innerHTML= "You will see your Dad</br>" + " <span>" + tuResult + "</span></br> " + "times before he is expected to die.";
  57. // }
  58. // if(document.getElementById("queridoAge").value == "" & (tu > country)){
  59. // document.getElementById("demo").innerHTML= "Your dad is living</br>" + " <span>" + tuOver + "</span></br> " + "years beyond the age he is expected to die.";
  60. // }
  61.  
  62.  
  63. // Validation
  64. if(document.getElementById("queridoAge").value == "" & document.getElementById("tuAge").value == ""){
  65. document.getElementById("demo").innerHTML= "You need to enter at least one of your parent's age.";
  66. }
  67. if(document.getElementById("userTime").value == ""){
  68. document.getElementById("demo").innerHTML= "You need to enter how many times a year you see your parents on average.";
  69. }
  70. if(document.getElementById("userTime").value == "0"){
  71. document.getElementById("demo").innerHTML= "You need to input a number larger than 0.";
  72. }
  73.  
  74.  
  75. // If Result is 0
  76. if(document.getElementById("queridoAge").value == country){
  77. document.getElementById("demo").innerHTML= "En su país tu familiar ha llegado a la esperanza media de vida.";
  78. }
  79. if(document.getElementById("tuAge").value == country){
  80. document.getElementById("demo").innerHTML= "Has llegado a la esperanza media de vida.";
  81. }
  82. if(maxEdad == country){
  83. document.getElementById("demo").innerHTML= "¡Aprovecha cada minuto que os queda poco tiempo!.";
  84. }
  85.  
  86. // If Result returns a NaN
  87. if (isNaN(queridoResult)) {
  88. document.getElementById("demo").innerHTML= "Ups...ha habido un error.";
  89. }
  90. if (isNaN(tuResult)) {
  91. document.getElementById("demo").innerHTML= "Ups...ha habido un error.";
  92. }
  93.  
  94. }
  95.  
  96. ///////////////////////////////
  97. // Limits input fields to numbers
  98. ///////////////////////////////
  99.  
  100.  
  101.  
  102. ///////////////////////////////
  103. // Div fade transitions
  104. ///////////////////////////////
  105.  
  106.  
  107. $('#btn').click(function(e){
  108. $('#calculator, .slogan').fadeOut('slow', function(){
  109. $('#results').fadeIn('slow');
  110. });
  111. });
  112.  
  113.  
  114. $('#btnNext').click(function(e){
  115. $('#results').fadeOut('slow', function(){
  116. $('#calculator,.slogan, h1').fadeIn('slow');
  117. });
  118. });
  119.  
  120.  
  121. $('#btnStart').click(function(e){
  122. $('#worldResults').fadeOut('slow', function(){
  123. $('#calculator ,.slogan, h1').fadeIn('slow');
  124. });
  125. });
  126.  
  127.  
  128. // fade in #back-top
  129. $(function () {
  130.  
  131. // scroll body to 0px on click
  132. $('#btn').click(function () {
  133. $('body,html').animate({
  134. scrollTop: 0
  135. }, 800);
  136. return false;
  137. });
  138.  
  139. // scroll body to 0px on click
  140. $('#btnNext').click(function () {
  141. $('body,html').animate({
  142. scrollTop: 0
  143. }, 800);
  144. return false;
  145. });
  146. });
  147.  
  148.  
  149. ///////////////////////////////
  150. // Country dropdown styles
  151. ///////////////////////////////
  152.  
  153.  
  154. $(function(){
  155. $('select.styled').customSelect();
  156. });
  157.  
  158.  
  159. ///////////////////////////////
  160. // Share Buttons
  161. ///////////////////////////////
  162.  
  163.  
  164. $('.popup').click(function(event) {
  165. var width = 575,
  166. height = 400,
  167. left = ($(window).width() - width) / 2,
  168. top = ($(window).height() - height) / 2,
  169. url = this.href,
  170. opts = 'status=1' +
  171. ',width=' + width +
  172. ',height=' + height +
  173. ',top=' + top +
  174. ',left=' + left;
  175.  
  176. window.open(url, 'twitter', opts);
  177.  
  178. return false;
  179. });
  180.  
  181.  
  182. ///////////////////////////////
  183. // Stellar Scroll
  184. ///////////////////////////////
  185.  
  186. jQuery(document).ready(function ($) {
  187.  
  188.  
  189. //initialise Stellar.js
  190. $(window).stellar();
  191.  
  192. //Cache some variables
  193. var links = $('.navigation').find('li');
  194. slide = $('.slide');
  195. button = $('.button');
  196. mywindow = $(window);
  197. htmlbody = $('html,body');
  198.  
  199.  
  200. //Setup waypoints plugin
  201. slide.waypoint(function (event, direction) {
  202.  
  203. //cache the variable of the data-slide attribute associated with each slide
  204. dataslide = $(this).attr('data-slide');
  205.  
  206. //If the user scrolls up change the navigation link that has the same data-slide attribute as the slide to active and
  207. //remove the active class from the previous navigation link
  208. if (direction === 'down') {
  209. $('.navigation li[data-slide="' + dataslide + '"]').addClass('active').prev().removeClass('active');
  210. }
  211. // else If the user scrolls down change the navigation link that has the same data-slide attribute as the slide to active and
  212. //remove the active class from the next navigation link
  213. else {
  214. $('.navigation li[data-slide="' + dataslide + '"]').addClass('active').next().removeClass('active');
  215. }
  216.  
  217. });
  218.  
  219. //waypoints doesnt detect the first slide when user scrolls back up to the top so we add this little bit of code, that removes the class
  220. //from navigation link slide 2 and adds it to navigation link slide 1.
  221. mywindow.scroll(function () {
  222. if (mywindow.scrollTop() == 0) {
  223. $('.navigation li[data-slide="1"]').addClass('active');
  224. $('.navigation li[data-slide="2"]').removeClass('active');
  225. }
  226. });
  227.  
  228. //Create a function that will be passed a slide number and then will scroll to that slide using jquerys animate. The Jquery
  229. //easing plugin is also used, so we passed in the easing method of 'easeInOutQuint' which is available throught the plugin.
  230. function goToByScroll(dataslide) {
  231. htmlbody.animate({
  232. scrollTop: $('.slide[data-slide="' + dataslide + '"]').offset().top
  233. }, 1400, 'easeInOutQuint');
  234. }
  235.  
  236.  
  237.  
  238. //When the user clicks on the navigation links, get the data-slide attribute value of the link and pass that variable to the goToByScroll function
  239. links.click(function (e) {
  240. e.preventDefault();
  241. dataslide = $(this).attr('data-slide');
  242. goToByScroll(dataslide);
  243. });
  244.  
  245. //When the user clicks on the button, get the get the data-slide attribute value of the button and pass that variable to the goToByScroll function
  246. button.click(function (e) {
  247. e.preventDefault();
  248. dataslide = $(this).attr('data-slide');
  249. goToByScroll(dataslide);
  250.  
  251. });
  252.  
  253.  
  254. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement