index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. $(document).ready(function() {
  2. var $api = $('.api');
  3. var $start = $('.start');
  4. var $show = $('.api .show');
  5. var $hide = $('.api .hide');
  6. var width = $(window).width();
  7. var height = $(window).height();
  8. var THRESHOLD = 700;
  9. init();
  10. $(window).on('resize', function() {
  11. width = $(window).width();
  12. height = $(window).height();
  13. init();
  14. });
  15. function init() {
  16. if (width < THRESHOLD) {
  17. $api.addClass('fullscreen');
  18. $start.addClass('full');
  19. } else {
  20. $api.removeClass('fullscreen');
  21. $start.removeClass('full');
  22. }
  23. if ($api.attr('class').indexOf('hidden') === -1) {
  24. showAPI();
  25. } else {
  26. hideAPI();
  27. }
  28. }
  29. function hideAPI() {
  30. $api.addClass('hidden');
  31. if (width >= THRESHOLD) {
  32. $start.addClass('full');
  33. }
  34. $start.removeClass('hidden');
  35. $hide.hide();
  36. $show.show();
  37. }
  38. function showAPI() {
  39. $api.removeClass('hidden');
  40. if (width >= THRESHOLD) {
  41. $start.removeClass('full');
  42. }
  43. $start.addClass('hidden');
  44. $show.hide();
  45. $hide.show();
  46. }
  47. $('body').on('click', '.hide', function() {
  48. hideAPI();
  49. });
  50. $('body').on('click', '.hidden', function() {
  51. showAPI();
  52. });
  53. });