04.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. $(document).ready(function () {
  2. "use strict";
  3. var $speech = $('div.speech');
  4. var defaultSize = $speech.css('fontSize');
  5. $('#switcher button').click(function () {
  6. var num = parseFloat($speech.css('fontSize'));
  7. switch (this.id) {
  8. case 'switcher-large':
  9. num *= 1.4;
  10. break;
  11. case 'switcher-small':
  12. num /= 1.4;
  13. break;
  14. default:
  15. num = parseFloat(defaultSize);
  16. }
  17. $speech.animate({fontSize: num + 'px'}, 'slow');
  18. });
  19. var $firstPara = $('p').eq(1);
  20. $firstPara.hide();
  21. $('a.more').click(function (event) {
  22. event.preventDefault();
  23. $firstPara.animate({
  24. opacity: 'toggle',
  25. height: 'toggle'
  26. }, 'slow');
  27. var $link = $(this);
  28. if ($link.text() == 'read more') {
  29. $link.text('read less');
  30. } else {
  31. $link.text('read more');
  32. }
  33. });
  34. $('div.label').click(function () {
  35. var paraWidth = $('div.speech p').outerWidth();
  36. var $switcher = $(this).parent();
  37. var switcherWidth = $switcher.outerWidth();
  38. $switcher
  39. .css({position: 'relative'})
  40. .fadeTo('fast', 0.5)
  41. .animate({
  42. left: paraWidth - switcherWidth
  43. }, {
  44. duration: 'slow',
  45. queue: false
  46. })
  47. .fadeTo('slow', 1.0)
  48. .slideUp('slow', function () {
  49. $switcher.css({backgroundColor: '#f00'});
  50. })
  51. .slideDown('slow');
  52. });
  53. $('p').eq(2)
  54. .css('border', '1px solid #333')
  55. .click(function () {
  56. var $clickedItem = $(this);
  57. $clickedItem.next().slideDown('slow', function () {
  58. $clickedItem.slideUp('slow');
  59. });
  60. });
  61. $('p').eq(3).css('backgroundColor', '#ccc').hide();
  62. $('body').fadeTo('slow', 1);
  63. $('p').hover(function () {
  64. $(this).toggleClass('highlighted');
  65. });
  66. $('h2').click(function (event) {
  67. var $h2 = $(this);
  68. $h2.css('position', 'relative');
  69. $h2.animate({
  70. opacity: '0.25',
  71. left: '20px'
  72. }, 'slow', 'swing', function () {
  73. $('.speech').animate({'opacity': '0.5'}, 'slow');
  74. });
  75. });
  76. var $switcher = $('#switcher');
  77. // Make the switcher movable, and readable even over other text.
  78. $switcher.css({
  79. position: 'relative',
  80. backgroundColor: 'white',
  81. opacity: 0.8
  82. });
  83. $(document).keydown(function (event) {
  84. var move;
  85. switch (event.which) {
  86. case 37: move = {left: '-=20px'}; break;
  87. case 38: move = {top: '-=20px'}; break;
  88. case 39: move = {left: '+=20px'}; break;
  89. case 40: move = {top: '+=20px'}; break;
  90. }
  91. $switcher.animate(move, 'fast');
  92. });
  93. });