This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
en:web_development:media:javascript [2021/12/18 08:50] mag created |
en:web_development:media:javascript [2023/08/16 09:33] (current) |
||
|---|---|---|---|
| Line 127: | Line 127: | ||
| * You may want to add audio when a user makes an action such as a correct (or incorrect) response to a quiz. For this you'd use Javascript to control your audio file. | * You may want to add audio when a user makes an action such as a correct (or incorrect) response to a quiz. For this you'd use Javascript to control your audio file. | ||
| * Let's simplify this by adding a button and playing or pausing the audio whenever the button is clicked. | * Let's simplify this by adding a button and playing or pausing the audio whenever the button is clicked. | ||
| - | < | + | < |
| * A button is a type of input. | * A button is a type of input. | ||
| * The < | * The < | ||
| Line 150: | Line 150: | ||
| * Variables in PHP are always represented by < | * Variables in PHP are always represented by < | ||
| * In this case, we have a variable named ' | * In this case, we have a variable named ' | ||
| - | * Now open ' | + | |
| + | |||
| + | < | ||
| + | $page = " | ||
| + | echo $page; | ||
| + | include(" | ||
| + | include(" | ||
| + | ?></ | ||
| + | |||
| + | * When you save, upload and run the code, you'll see the word ' | ||
| + | * The code in ' | ||
| + | | ||
| < | < | ||
| * Notice that the only change we've made is to the word ' | * Notice that the only change we've made is to the word ' | ||
| Line 171: | Line 182: | ||
| audio.play(); | audio.play(); | ||
| }</ | }</ | ||
| + | * Give that a try before we add the pause option. | ||
| + | * Now, we first want to check the state of the audio (playing or paused) before we decide which action to take. | ||
| + | < | ||
| + | * This code will check whether our audio is < | ||
| + | * Can you complete this function without looking at the code below? | ||
| + | < | ||
| + | var audio = document.getElementsByTagName(' | ||
| + | if (audio.paused) { | ||
| + | audio.play(); | ||
| + | } else { | ||
| + | audio.pause(); | ||
| + | } | ||
| + | }</ | ||
| + | * We'll save controlling the video by Javascript for a exercise. | ||
| + | |||
| + | [[en: | ||