Page 1 of 1
How to focus without moving the scrollbar?
Posted: Tue Mar 17, 2009 2:23 am
by lovelf
Is it possible to set focus on an element without moving the scrollbar if this element is below available height ?
Code: Select all
<textarea id="rfz" style="position:absolute;bottom:-100px;"></textarea>
Code: Select all
<script type="text/javascript">
function rfz(){document.getElementById("rfz").focus();}
setTimeout(rfz,0);
</script>
Re: How to focus without moving the scrollbar?
Posted: Tue Mar 17, 2009 3:46 am
by volomike
I don't think so. Let's look at this from a different angle. What is it that you are trying to do that would cause you to go down this road in the first place?
Re: How to focus without moving the scrollbar?
Posted: Tue Mar 17, 2009 4:56 am
by lovelf
To use it as an incentive for people to write comments.
The comments textarea is below the articles and I would like to have focus on it but without the scrollbar going down to where the textarea is.
Thanks.
Re: How to focus without moving the scrollbar?
Posted: Tue Mar 17, 2009 5:10 am
by papa
How about using an anchor (<a name>) and let people decide wether they want to write a comment or not? An easy way to make the page jump down to the comments field if the article is long.
Re: How to focus without moving the scrollbar?
Posted: Tue Mar 17, 2009 6:37 am
by lovelf
Yes, when the anchor is clicked then the focus is set to the textarea.
Re: How to focus without moving the scrollbar?
Posted: Tue Mar 17, 2009 6:43 am
by papa
Sounds nice.