-
Notifications
You must be signed in to change notification settings - Fork 107
/
reveal-steps.html
117 lines (104 loc) · 2.81 KB
/
reveal-steps.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width">
<title>MathJax v3 dynamic equations using CSS and javascript</title>
<script>
MathJax = {
tex: {inlineMath: [['$', '$'], ['\\(', '\\)']]},
chtml: {
displayAlign: 'left'
},
startup: {
pageReady: function () {
//
// Do the usual startup (which does a typeset).
// When that is all done, un-hide the page.
//
return MathJax.startup.defaultPageReady().then(function () {
document.getElementById("hidden").disabled = true;
});
}
}
};
</script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
<script type="text/javascript">
//
// Use a closure to hide the local variable
//
(function () {
var n = 1;
//
// Make the current step be visible, and increment the step.
// If it is the last step, disable the step button.
// Once a step is taken, the reset button is made available.
//
window.ShowStep = function () {
document.getElementById("Step" + n++).style.visibility = "visible";
if (!document.getElementById("Step" + n)) {
document.getElementById("step").disabled = true;
}
document.getElementById("reset").disabled = false;
}
//
// Enable the step button and disable the reset button.
// Hide the steps.
//
window.ResetSteps = function () {
document.getElementById("step").disabled = false;
document.getElementById("reset").disabled = true;
var i = 1, step; n = 1;
while (step = document.getElementById("Step" + i)) {
step.style.visibility = "hidden";
i++
}
}
})();
</script>
<style>
/*
* Start with the steps being hidden
*/
#Step1, #Step2, #Step3, #Step4, #Step5 {
visibility: hidden;
}
h1 {
background: #CCCCCC;
padding: .2em 1em;
border-top: 3px solid #666666;
border-bottom: 3px solid #999999;
}
#frame {
margin-left: 2em;
}
</style>
<style id="hidden">
body {
visibility: hidden;
}
</style>
</head>
<body>
<h1>Dynamic Equations in MathJax</h1>
<div id="frame">
<p>
Expand the following:
\begin{align}
(x+1)^2
&= \cssId{Step1}{(x+1)(x+1)} \\[3px]
&\cssId{Step2}{{} = x(x+1) + 1(x+1)} \\[3px]
&\cssId{Step3}{{} = (x^2+x) + (x+1)} \\[3px]
&\cssId{Step4}{{} = x^2 + (x + x) + 1} \\[3px]
&\cssId{Step5}{{} = x^2 + 2x + 1}
\end{align}
</p>
<p>
<input type="button" onclick="ShowStep()" value="Show Next Step" id="step" />
<input type="button" onclick="ResetSteps()" value="Reset" id="reset" disabled="true" />
</p>
</div>
</body>
</html>