logo, sports bar, jquery event handler

This commit is contained in:
Tim Wijma
2022-10-31 20:36:08 +01:00
parent dc14ab714e
commit c6ffc8f3ff
5 changed files with 147 additions and 11 deletions

View File

@@ -0,0 +1,23 @@
let root = document.documentElement // Used for css variables
let selectedSports = []
$(".sport").on("click", function() {
$(this).toggleClass("selected")
let sportName = $(this).children()[1].innerHTML // 2nd element, which is the sport name
let index = selectedSports.indexOf(sportName)
if (index > -1 ) { // If element is found in array
selectedSports.splice(index, 1) // Remove sport at index
} else {
selectedSports.push(sportName) // Add sport to array
}
$(this).trigger("selected", [selectedSports.includes(sportName), selectedSports]) // Trigger event
})
function getCSSVariable(name) {
return getComputedStyle(root).getPropertyValue(name)
}