On my gallery page at my other website I have an index that slides in across the page, so that a user can easily access any image set they like at any time.
Example index
Here's a dummy gallery with the index, with buttons that highlight according to which thumbnail is selected...
Index
×
Group1
Subject1
1A
1B
Subject2
2A
2B
Subject3
3A
3B
Subject4
4A
4B
Group2
Subject5
5A
5B
Subject6
6A
6B
Subject7
12A
7B
Subject8
8A
8B
1A
1B
2A
2B
3A
3B
4A
4B
5A
5B
6A
6B
7A
7B
8A
8B
The basic idea is that a mouse-over on the 'index' button is detected by js, which then sets the css class 'visible' to the index div, causing it to transform to its position set in the css across the screen, from its normal position off the screen. When the mouse moves off the index button or any of its child divs, or an index item is clicked, the 'visible' class is removed and the menu transforms back to its normal off-screen position.
But there is a notable problem, that you would find immediately with such a simple construct, which is that after clicking on an index item, the index then slides off-screen, but in the process it catches the mouse hover on it and it returns back over the screen, giving the feeling it's stuck, and you can't move the mouse fast enough to stop it.
Maybe you could use a time delay to prevent another mouse hover event (actually I didn't try that as a solution, I only just thought of it). But what I did was to set an argument in the mouse-over listener function, to make it work only if the variable 'clicked' is false. When clicking on an item, the variable is set to true and the mouse-over event will not trigger.
But that means that after clicking an item and the 'clicked' var is set to true, you will not be able to trigger the mouse-over again on the index button, until the variable is made false. So what I did was to surround the index button with a small div, and set a js listener event to it, which sets the variable to false on mouse-over. So the mouse has to pass over it to reach the index button and the var is set false, so that the menu can display.
Here is my javascript...
A few notes..
I use the 'stopscroll' and 'resumescroll' fn's I made before with the lightbox js, to prevent the page scrolling up and down when the mouse scroll button is used on the index.
The fn part 'submenu.scrollTop' makes sure that the index returns to the top if it was scrolled down to find an entry and clicked, so that when it is called again it looks neat and not stuck at the bottom.
The 'clicked = false;' variable setting at top might not be needed, since I have a listener on mouse over on the 'mouse-reset' div.
The 'closeindex' fn at the bottom is called by a click on a 'X' on the index top corner, with the 'close-index' css class (see the page layout below).
For touch screens, the index button is tapped and there is no mouse-over event to trigger the index.
So I add this js segment below to the script...
And the index page layout looks something like this..
View code
The index buttons...
View code
And the CSS..
View code
The index animation here is really simple, you could always fade it in or expand from the top corner or spin it orsomething.
Buttons
Notice that the buttons on the index each have their own id. This id needs to be identical to the argument sent by each button or thumbnail which is caught by js as 'target', and is used by the script to fetch new html (see my One page image gallery page ).
Being identical to the 'target' value makes the process simple, as we then declare in the script that id = `${target}` , which is a value sent by the correct button.
We use this var 'id' to set the class 'activeIndex' and 'activeLine' to the element with the id matching the 'target' called by the onClick.
The js first clears all buttons/lines of the style class to make sure none are highlighted, then it applies the highlight to the new active button and its line (using closest sibling).
Note that alll the buttons in the gallery are caling 'fetchHtml' and so the js snippet below should be placed inside that fn, to pick up the 'target' argument sent by the click. (I'm not fetching html on this page however.)
On this page, I also add id's to the thumbnails, like 'id=01aT' (adding a 'T'). Then I make a new var called id1, and set a 'focus' class to the thumbnail with the id. The js first removes the class from all the thumbs...