Forum Discussion
Using multiple sliders as an alternative to drag-and-drop, with dynamic Z-index control
- 9 months ago
I absolutely love this interactivity—great job, Jonathan!
That said, I did notice some inconsistencies with the "z-index" values throughout the activity. For example, when the goblet is moved, it correctly passes in front of the knife and fork. However, once it’s "dropped" or stationary, the fork or knife moves in front of the goblet when either of them is dragged. Upon debugging, it seems that the "z-index" is being reset to its initial value whenever an element is dropped or stops being moved.
After analyzing the scene further, I believe the fork and knife should never pass beneath each other when switching positions. In real life, with one hand (or slider in this case), we’d lift and reposition one object at a time without either going underneath the other. But that’s just my perspective—hope you don’t mind these little observations!Anyway, since all the actions occur when either slider moves, I tried to come up with a JavaScript solution to address this issue overall and ensure the code executes whenever either slider is moved. This way, the fork and knife never pass in front of the goblet. Additionally, the fork never passes beneath the knife when switching positions with it, and the knife never passes beneath the fork when switching positions with the fork.
Example:const goblet = document.querySelector("[data-model-id='5xjQeS51pKT']"); const fork = document.querySelector("[data-model-id='6CjWcCjhI4H']"); const knife = document.querySelector("[data-model-id='6jDKIpbtGdv']"); function logZIndexChange(element, newZIndex) { let currentZIndex = window.getComputedStyle(element).zIndex; console.log(`${element.getAttribute('data-model-id')} - Current z-index: ${currentZIndex}`); element.style.setProperty("z-index", newZIndex, "important"); let updatedZIndex = window.getComputedStyle(element).zIndex; console.log(`${element.getAttribute('data-model-id')} - New z-index: ${updatedZIndex}`); } logZIndexChange(goblet, "300"); // keep it same for all three triggers logZIndexChange(fork, "100"); // 100 when the KNIFE moves. 200 when the FORK moves logZIndexChange(knife, "200"); // 200 when the KNIFE moves, 100 when the FORK moves // Of course, these values can be anything, as long as we understand the concept and know what we’re doing here.
Once again, thank you for sharing this with the community. I’ve learned so much from your example!
Hi Jonathan,
Fabulous approach to creating an accessible option to drag-and-drop.
Could this less-imaginative application work:
Stack the objects vertically on the left.
To the right of each object have a slider.
Across the top use labels to create the sense of labeled columns. So the learner would move each slider into the appropriate “column”.
For example: On the right is a vertical stack of images of a cat, dog, and bird. To the right of each one is a slider extending into the “columns.” So the learner must move the cat slider into the cat “column;” the dog slider into the Dog “column” and so on.
Hey JohnMorley-a8f1, yes, in principle that would be a good approach. You'd have to consider how stacking the sliders on top of each other, with them all starting on the left, might inhibit how 'grabbable' the items are. I imagine you'd need to give each item a clear track or lane.
I get round this here as the items are all different sizes and aren't stacked directly on top of each other. The logic of moving the slider thumb to a certain position to complete an activity is sound, though.
I did a similar thing here:
I also went down a bit of a rabbit hole recently exploring how three sliders can directly overlap and remain 'grabbable'...
'Cup and Ball' game using sliders with dynamic Z-index control | Articulate - Community
I'd be interested to see your own experiments in this area, John.
Related Content
- 8 months ago
- 3 months ago