Here is my HTML structure:
<body>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<div class='error'>error message</div>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
</body>
Here is my CSS code:
.error{
display: none;
}
Here is my Jquery code:
// detect pressing enter on keyboard
$(document).keypress(function(e) {
if(e.which == 13) {
$('.error').show();
}
});
What the above code does: when user press <enter>
, <div>
will be shown.
What I want: when <div>
shown, if it was in the screen then nothing, but if it was not in the screen, page scrolls and stops where <div>
is in the screen, how can I do that?
It should be noted that I don't want this: position: fixed;
` in reality, it is just a test. – Shafizadeh Sep 24 '15 at 09:25