468,243 Members | 2,035 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,243 developers. It's quick & easy.

"IsInview" function?

Has anyone come up with an "IsInview" function that one could use to
test whether scrollIntoView is needed?

Imagine a (scrolled) list of editable item prices. I want to impose
maximum and minimum limits - so I test the just-changed value when the
user either starts to edit another field, or tries to close the form.

If there is an error, I need to highlight the error - and that means
scrolling back to the problem item if it is not in view. Simple enough.

BUT if the item is ALREADY in view, I don't want to do a scrollIntoView
because that will move the item to the top or bottom of the scrollable
area (depending on the parameter setting) - when the item is already
happily displayed within the visible area. The user would see the list
move when there is no need to do anything other than highlight the field
as problematic.

But how to test whether a particular element is currently "in view"? Ideas?

John Geddes
England
Sep 18 '08 #1
2 3059
John Geddes wrote:
Has anyone come up with an "IsInview" function that one could use to
test whether scrollIntoView is needed?

Imagine a (scrolled) list of editable item prices. I want to impose
maximum and minimum limits - so I test the just-changed value when the
user either starts to edit another field, or tries to close the form.

If there is an error, I need to highlight the error - and that means
scrolling back to the problem item if it is not in view. Simple enough.
The focus() method will scroll the element into view, only if needed.

In fact, for those wishing to implement a 'scrollIntoViewIfNeeded' (ala
Safari), this is the way to do it. It will work even in old browsers
where scrollIntoView is not available or broken (mac IE).

Take care not to create an infinite loop. The focus method fires onfocus.

Garrett
John Geddes
England
Sep 19 '08 #2
dhtml wrote:
John Geddes wrote:
>Has anyone come up with an "IsInview" function that one could use to
test whether scrollIntoView is needed?

Imagine a (scrolled) list of editable item prices. I want to impose
maximum and minimum limits - so I test the just-changed value when the
user either starts to edit another field, or tries to close the form.

If there is an error, I need to highlight the error - and that means
scrolling back to the problem item if it is not in view. Simple enough.

The focus() method will scroll the element into view, only if needed.

In fact, for those wishing to implement a 'scrollIntoViewIfNeeded' (ala
Safari), this is the way to do it. It will work even in old browsers
where scrollIntoView is not available or broken (mac IE).

Take care not to create an infinite loop. The focus method fires onfocus.

Garrett
>John Geddes
England
Just a note for posterity (after some painful experimentation) - focus
is great (and ideal in mycase), but note that it only applies to TEXT
OBJECTS(<input type="text">) while scrollIntoView will work on a <div>
or <pfor example.

John Geddes

Sep 25 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by domeceo | last post: by
5 posts views Thread by phil_gg04 | last post: by
2 posts views Thread by laredotornado | last post: by
2 posts views Thread by sushil | last post: by
8 posts views Thread by Olov Johansson | last post: by
3 posts views Thread by Beta What | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.