Reputation: 5411
When I'm trying input.focus();
on form input with error. The cursor points on that input but Since I have a fixed header whose height is around 100px,the input field is not visible.
Is there a way where I can go beyond that input fields something like input.focus(-100);
?
I have also tried input.scrollTop();
but it doesn't go any where near that input.
Upvotes: 0
Views: 118
Reputation: 9646
Something like this: http://jsfiddle.net/AzRwm/
<style>
#h{
background:black;
height:100px;
position:fixed;
width:100%;
}
#s{
height:800px;
}
</style>
<header id='h'></header>
<div id="s"></div>
<input id="i" value='test' />
<script>
var i = document.getElementById('i');
window.scrollTo(0,i.offsetTop + 100);
</script>
Upvotes: 1
Reputation: 1195
here is some idea.
var top = input.offset().top - 100; // or input.position().top + 100;
$(document).scrollTop(top);
Upvotes: 1