-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
65 lines (57 loc) · 1.94 KB
/
script.js
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
var plusmin = 1;
$(document).ready(function() {
// when click on the element with id="idd"
var stl = localStorage.getItem("color-mode");
if (stl == null) {
localStorage.setItem("color-mode", "styles.css");
}
var stl = localStorage.getItem("color-mode");
$('#stl[rel=stylesheet]').attr('href', stl);
$('#idd').click(function(){
plusmin *= -1; // change the polarity of "plusmin" var
stl = plusmin>0 ? 'styles.css' : 'styles2.css'; // sets the css file, according to plusmin
// change the css file of the tag with id="stl" and rel="stylesheet"
$('#stl[rel=stylesheet]').attr('href', stl);
localStorage.setItem("color-mode", stl);
});
});
//<JQCode examples="and">Tutorials</JQCode>
var i = 0;
var width_now = 0
function animateProgress(percentage, color) {
if (i == 0) {
i = 1;
var elem = document.getElementById("progressBar");
elem.style.backgroundColor = color;
var width = width_now;
var id = setInterval(frame, 18);
function frame() {
if (width >= percentage) {
clearInterval(id);
i = 0;
} else {
width++;
elem.style.width = width + "%";
elem.innerHTML = width + "%";
}
}
}
}
function checkAnswer(quiz_option, quiz_progress) {
document.getElementById("next").style.display = "inline";
var av = document.getElementById(quiz_option);
document.getElementById("option1").disabled = true;
document.getElementById("option2").disabled = true;
document.getElementById("option3").disabled = true;
document.getElementById("option4").disabled = true;
if (av.checked == true) { //correct answer is selected
animateProgress(quiz_progress * 100, "green");
} else {
animateProgress(quiz_progress * 100, "red");
}
}
function setProgress(percentage) {
document.getElementById("progressBar").style.width = percentage + "%";
document.getElementById("progressBar").innerHTML = percentage + "%";
width_now = percentage
}