Compare commits
32 Commits
Author | SHA1 | Date |
---|---|---|
|
42cd4def25 | 8 years ago |
|
43488eeaea | 8 years ago |
|
0336132c61 | 8 years ago |
|
4f58ad1fe5 | 8 years ago |
|
eb209062e2 | 8 years ago |
|
71e29f11e0 | 8 years ago |
|
4764a09973 | 8 years ago |
|
309de303d0 | 8 years ago |
|
50ad6cc1c5 | 8 years ago |
|
2ac097d1ac | 8 years ago |
|
ba764541e2 | 8 years ago |
|
f6a2117f78 | 8 years ago |
|
c6c2d8603f | 8 years ago |
|
030b3dad90 | 8 years ago |
|
a66d9832f6 | 8 years ago |
|
725a770a94 | 8 years ago |
|
69ab2f12d0 | 8 years ago |
|
7098962ce3 | 8 years ago |
|
12ccebe93c | 8 years ago |
|
a0c30c23ad | 8 years ago |
|
e1e7877f94 | 8 years ago |
|
34474839ec | 8 years ago |
|
25674b5ce6 | 8 years ago |
|
36ebf6f0b4 | 8 years ago |
|
8cfc31392b | 8 years ago |
|
480f94030e | 8 years ago |
|
a5bc7aa76c | 8 years ago |
|
d489b8e893 | 8 years ago |
|
eec0a7ed3d | 8 years ago |
|
549e267eea | 9 years ago |
|
a68eb6a985 | 9 years ago |
|
a3fcfe763f | 9 years ago |
@ -1,23 +1,80 @@ |
|||||||
document.addEventListener("DOMContentLoaded",()=>{ |
(function() { |
||||||
document.getElementById("controls").addEventListener("click",(clicked)=>{ |
'use strict'; |
||||||
var lightPrefix = clicked.target.id.replace("Button",""); |
|
||||||
var targetLight = document.getElementById(lightPrefix+"Light"); |
const stopButton = document.querySelector('#stopButton'); |
||||||
if (!targetLight.classList.contains(lightPrefix)) { |
const slowButton = document.querySelector('#slowButton'); |
||||||
targetLight.classList.add(lightPrefix); |
const goButton = document.querySelector('#goButton'); |
||||||
console.log(lightPrefix+" bulb on.") |
|
||||||
} else { |
const stopLight = document.querySelector('#stopLight'); |
||||||
targetLight.classList.remove(lightPrefix); |
const slowLight = document.querySelector('#slowLight'); |
||||||
console.log(lightPrefix+" bulb off.") |
const goLight = document.querySelector('#goLight'); |
||||||
} |
|
||||||
}) |
// part 1
|
||||||
|
stopButton.addEventListener('click', () => { |
||||||
var buttons = document.getElementsByClassName("button"); |
stopLight.classList.toggle('stop'); |
||||||
for (var i=0;i<buttons.length;i++) { |
|
||||||
buttons[i].addEventListener("mouseenter",(e)=>{ |
// or...
|
||||||
console.log("Entered "+e.target.innerHTML+" button.") |
// if (stopLight.classList.contains('stop')) {
|
||||||
}) |
// stopLight.classList.remove('stop');
|
||||||
buttons[i].addEventListener("mouseleave",(e)=>{ |
// }
|
||||||
console.log("Left "+e.target.innerHTML+" button.") |
// else {
|
||||||
}) |
// stopLight.classList.add('stop');
|
||||||
} |
// }
|
||||||
}) |
}); |
||||||
|
|
||||||
|
slowButton.addEventListener('click', () => { |
||||||
|
slowLight.classList.toggle('slow'); |
||||||
|
}); |
||||||
|
|
||||||
|
goButton.addEventListener('click', () => { |
||||||
|
goLight.classList.toggle('go'); |
||||||
|
}); |
||||||
|
|
||||||
|
// part 2
|
||||||
|
const handleMouseEnter = (event) => { |
||||||
|
console.log(`Entered ${event.target.textContent} button`); |
||||||
|
}; |
||||||
|
|
||||||
|
const handleMouseLeave = (event) => { |
||||||
|
console.log(`Left ${event.target.textContent} button`); |
||||||
|
}; |
||||||
|
|
||||||
|
stopButton.addEventListener('mouseenter', handleMouseEnter); |
||||||
|
slowButton.addEventListener('mouseenter', handleMouseEnter); |
||||||
|
goButton.addEventListener('mouseenter', handleMouseEnter); |
||||||
|
|
||||||
|
stopButton.addEventListener('mouseleave', handleMouseLeave); |
||||||
|
slowButton.addEventListener('mouseleave', handleMouseLeave); |
||||||
|
goButton.addEventListener('mouseleave', handleMouseLeave); |
||||||
|
|
||||||
|
// bonus
|
||||||
|
const controls = document.querySelector('#controls'); |
||||||
|
|
||||||
|
controls.addEventListener('click', (event) => { |
||||||
|
if (event.target === controls) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
let status; |
||||||
|
|
||||||
|
if (event.target === stopButton) { |
||||||
|
status = stopLight.classList.contains('stop') ? 'on' : 'off'; |
||||||
|
|
||||||
|
// or...
|
||||||
|
// if (stopLight.classList.contains('stop')) {
|
||||||
|
// status = 'on';
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// status = 'off';
|
||||||
|
// }
|
||||||
|
} |
||||||
|
else if (event.target === slowButton) { |
||||||
|
status = slowLight.classList.contains('slow') ? 'on' : 'off'; |
||||||
|
} |
||||||
|
else { |
||||||
|
status = goLight.classList.contains('go') ? 'on' : 'off'; |
||||||
|
} |
||||||
|
|
||||||
|
console.log(`${event.target.textContent} bulb ${status}`); |
||||||
|
}); |
||||||
|
})(); |
||||||
|
Loading…
Reference in new issue