I am trying to move each <li>
to top of the screen on onClick()
, and its working using scrollIntoView();
but because my header is fixed small part of the <li>
goes below the header. How can I scroll the <li>
to just below the header.
HTML
<header></header>
<div id="wrapper">
<ul>
<li id='li1' onClick="moveup(1)"> blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
</li>
<li id='li2' onClick='moveUp(2)'> blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
</li>
<li id='li3' onClick='moveUp(3)'> blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
</li>
<li id='li4' onClick='moveUp(4)'> blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
</li>
<li id='li1' onClick='moveUp(1)'> blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
</li>
<li id='li5' onClick='moveUp(5)'> blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
blah blah blah blah blah <br/>
</li>
</ul>
</div> <!--end wrapper-->
css
header {
position: fixed;
top: 0;
right: 0;
left: 0;
height: 50px;
background-color: red;
}
#wrapper {
width: 1000px;
background-color: blue;
height: 100%;
margin: 0 auto;
}
#col1 {
background-color: green;
height: 100%;
width: 80%;
margin: 0 auto;
}
ul {
margin: 0 auto;
width: 500px;
display: block;
}
li {
display: block;
background-color: yellow;
height: 500px;
width: 500px;
margin-bottom: 5px;
}
JAVASCRIPT
function moveup(x){
document.getElementById('li'+x).scrollIntoView();
}
http://jsfiddle.net/Jn74M/2/
Thanks.
After scrollIntoView()
, push it down by 50px, using something like this:
scrollBy(0, -50);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With