I have a search bar at the top of a navigable table, which I want the position to be fixed so it is still visible while scrolling. The table puts itself over the search bar. I use scrollIntoView() in the table navigation script to move the view to the selected row. Here is a jsfiddle with the problem occuring: https://jsfiddle.net/5umztjty/
#screen {
position: relative;
z-index: 110;
width: 255px;
height: 140px;
overflow-y: hidden;
}
#pokemons-list {
padding-top: 3px;
border-spacing: 0px;
align-content: center;
position: absolute;
width: 100%;
}
#mySearch {
position: fixed;
}
<!-- begin snippet: js hide: false console: true babel: false -->
I also tried this fix Using scrollIntoView with a fixed position header
But it's still not working. In this case the selected element is a table row, so I have :
var rows = document.getElementById("myTable").children[1].children;
var selectedRow
var yourHeight = '20px';
so I wrote
// scroll to your element
rows[selectedRow].scrollIntoView(true);
// now account for fixed header
var scrolledY = window.scrollY; if(scrolledY) {
window.scroll(0, scrolledY - yourHeight);
}
I didn't put the navigation script but it works well (at the beginning the var selectedRow value is 0)