I feel like the main point of inefficiency is how I create "notches" and must loop through all of the created notches every time the value for the slider is changed.
function sliderLoop() {
for (var i = slideNotchArray.length - 1; i >= 0; i--) {
if ($(".slider").val() >= slideNotchArray[i].value) {
console.log(slideNotchArray[i].slide);
teamSlider.goTo(slideNotchArray[i].slide);
break;
}
}
}
It's an exponential nightmare as each call can loop through every notch object, and there can be multiple calls a second. This is the only solution I could have thought of though, and I am more than welcome to someone else's suggestions. I attempted to mitigate the severity by including a break once the first notch has been found, as to not loop through the rest, but I feel as though it is still quite heavy.
https://codesandbox.io/s/currying-bush-h3xyz
My major concerns are in relation to
function sliderLoop() {
for (var i = slideNotchArray.length - 1; i >= 0; i--) {
if ($(".slider").val() >= slideNotchArray[i].value) {
console.log(slideNotchArray[i].slide);
teamSlider.goTo(slideNotchArray[i].slide);
break;
}
}
}
// Fires slider loop every time the value changes, I had to use mousemove as .change() would only fire once the mouse click was relseased.
$(".slider").on("change mousemove", function() {
sliderLoop();
});
The "change mousemove" event listener, calls sliderLoop multiple times a second. sliderLoop() contains a for loop, which could potentially iterate through many (10+) array index's. Calling a for loop which iterates through so many index's multiple times a second makes me believe this is an inefficient method of going about a slider navigation, however, I am at a loss as to how to improve the code while maintaining the functionality. Would you believe this to be an issue worth worrying about? If so, how could I go about improving this?