sample-dynamic-steps.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>MathJax Dynamic Steps Test Page</title>
  5. <!-- Copyright (c) 2011-2015 The MathJax Consortium -->
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  8. <script type="text/x-mathjax-config">
  9. //
  10. // Make displayed equations be aligned left and indented
  11. //
  12. MathJax.Hub.Config({
  13. displayAlign: "left",
  14. displayIndent: "2em"
  15. });
  16. //
  17. // Enable the step button after the equation is typeset
  18. //
  19. MathJax.Hub.Queue(function () {
  20. document.getElementById("step").disabled = false;
  21. });
  22. </script>
  23. <script type="text/javascript" src="../MathJax.js?config=TeX-AMS_HTML-full"></script>
  24. <script type="text/javascript">
  25. //
  26. // Use a closure to hide the local variable
  27. //
  28. (function () {
  29. var n = 1;
  30. //
  31. // Make the current step be visible, and increment the step.
  32. // If it is the last step, disable the step button.
  33. // Once a step is taken, the reset button is made available.
  34. //
  35. window.ShowStep = function () {
  36. document.getElementById("Step"+n).style.visibility = "visible"; n++;
  37. if (!document.getElementById("Step"+n)) {document.getElementById("step").disabled = true}
  38. document.getElementById("reset").disabled = false;
  39. }
  40. //
  41. // Enable the step button and disable the reset button.
  42. // Hide the steps.
  43. //
  44. window.ResetSteps = function () {
  45. document.getElementById("step").disabled = false;
  46. document.getElementById("reset").disabled = true;
  47. var i = 1, step; n = 1;
  48. while (step = document.getElementById("Step"+i)) {step.style.visibility = "hidden"; i++}
  49. }
  50. })();
  51. </script>
  52. <style>
  53. /*
  54. * Start with the steps being hidden
  55. */
  56. #Step1, #Step2, #Step3, #Step4, #Step5 {
  57. visibility: hidden;
  58. }
  59. h1 {
  60. background: #CCCCCC;
  61. padding: .2em 1em;
  62. border-top: 3px solid #666666;
  63. border-bottom: 3px solid #999999;
  64. }
  65. </style>
  66. </head>
  67. <body>
  68. <h1>Dynamic Equations in MathJax</h1>
  69. <blockquote>
  70. <p>
  71. Expand the following:
  72. \begin{align}
  73. (x+1)^2
  74. &\cssId{Step1}{= (x+1)(x+1)}\\
  75. &\cssId{Step2}{= x(x+1) + 1(x+1)}\\
  76. &\cssId{Step3}{= (x^2+x) + (x+1)}\\
  77. &\cssId{Step4}{= x^2 + (x + x) + 1}\\
  78. &\cssId{Step5}{= x^2+2x+1}\\
  79. \end{align}
  80. </p>
  81. <input type="button" onclick="ShowStep()" value="Show Next Step" id="step" disabled="true" />
  82. <input type="button" onclick="ResetSteps()" value="Reset" id="reset" disabled="true" />
  83. </blockquote>
  84. </body>
  85. </html>