By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,505 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,505 IT Pros & Developers. It's quick & easy.

"IsInview" function?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.