04.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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(2000, 1);
  63. });