complete.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. $(document).ready(function() {
  2. var $speech = $('div.speech');
  3. var defaultSize = $speech.css('fontSize');
  4. $('#switcher button').click(function() {
  5. var num = parseFloat($speech.css('fontSize'));
  6. switch (this.id) {
  7. case 'switcher-large':
  8. num *= 1.4;
  9. break;
  10. case 'switcher-small':
  11. num /= 1.4;
  12. break;
  13. default:
  14. num = parseFloat(defaultSize);
  15. }
  16. $speech.animate({fontSize: num + 'px'}, 'slow');
  17. });
  18. var $firstPara = $('p').eq(1);
  19. $firstPara.hide();
  20. $('a.more').click(function() {
  21. $firstPara.animate({
  22. opacity: 'toggle',
  23. height: 'toggle'
  24. }, 'slow');
  25. var $link = $(this);
  26. if ($link.text() == 'read more') {
  27. $link.text('read less');
  28. } else {
  29. $link.text('read more');
  30. }
  31. return false;
  32. });
  33. $('div.label').click(function() {
  34. var paraWidth = $('div.speech p').outerWidth();
  35. var $switcher = $(this).parent();
  36. var switcherWidth = $switcher.outerWidth();
  37. $switcher
  38. .css({position: 'relative'})
  39. .fadeTo('fast', 0.5)
  40. .animate({
  41. left: paraWidth - switcherWidth
  42. }, {
  43. duration: 'slow',
  44. queue: false
  45. })
  46. .fadeTo('slow', 1.0)
  47. .slideUp('slow', function() {
  48. $switcher.css({backgroundColor: '#f00'});
  49. })
  50. .slideDown('slow');
  51. });
  52. $('p').eq(2)
  53. .css('border', '1px solid #333')
  54. .click(function() {
  55. var $clickedItem = $(this);
  56. $clickedItem.next().slideDown('slow', function() {
  57. $clickedItem.slideUp('slow');
  58. });
  59. });
  60. $('p').eq(3).css('backgroundColor', '#ccc').hide();
  61. });