I'm working with multiple ordered-lists <ol>
Each <ol>
has one <li>
with class .highlight
Problem:
Sometimes the highlighted <li>
is located somewhere down the scrollable <ol>
and therefor not visible.
highlighted list highlighted list
item not visible item visible
____________________ ____________________
| | | |
| browser window | | browser window |
|____________________| |____________________|
| | | |
| List: | | List: |
| 1. green | | 1. green |
| 2. blue | |** 2. blue ** |
| 3. red | | 3. red |
-------------------- --------------------
4. brown 4. brown
5. purple 5. purple
6. yellow 6. yellow
** 7. pink ** 7. pink
8. orange 8. orange
Solution?
Scroll the <li>
with class .highlight
to the top of each <ol>
else
At least scroll the <li>
with class .highlight
into view inside each <ol>
Project Link:
http://www.paintings.directory
Hover over image to add class .highlight
to corresponding list-items. (artist, artwork, year, ...)
Often the highlighted <li>
is located low inside the <ol>
and therefor I cannot see them. -_-"
How do I scroll into view the highlighted <li>
inside each <ol>
?
What I tried in jQuery:
$('ol > li.highlight').animate({ scrollTop: $('ol').height() }, "slow");
What I also tried in jQuery:
I tried implementing .scrollIntoView();
as follows:
$('img').hover(function() {
var classes = $(this).attr('class').split(" ").map(function(value) {
return "." + value;
}).join(",")
$('section > ol > li' + classes).addClass('highlight');
$('.highlight').scrollIntoView(); // <---
}, function() {
$('section > ol > li').removeClass('highlight');
});
Research:
I found these helpful, but was unable to implement properly: