Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var is_open = 0;
  2. var has_text = [false, false, true, true, true, true];
  3.  
  4. function open_close(n) {
  5.     var was_open = (n == is_open);
  6.     var will_show_text = (has_text[n-1] && !was_open); // must have text and needs to have been closed before
  7.     var base_opacity = will_show_text ? 0.3 : 1;
  8.  
  9.     // hide all
  10.     for(var i=0; i<is_open.length; ++i) {
  11.         document.getElementById('text'+(i+1)).style.visibility = 'hidden';
  12.         document.getElementById(i+1).style.opacity = base_opacity;
  13.         is_open[i] = false;
  14.     }
  15.  
  16.     if (will_show_text) {
  17.         document.getElementById('text'+n)).style.visibility = 'visible';
  18.         document.getElementById(n).style.opacity = '1';
  19.         is_open[n-1] = true;
  20.     }
  21. }
  22.  
  23. function myFunction() { open_close(1); }
  24. function myFunction2() { open_close(2); }
  25. function myFunction3() { open_close(3); }
  26. function myFunction4() { open_close(4); }
  27. function myFunction5() { open_close(5); }
  28. function myFunction6() { open_close(6); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement