"IsInview" function?

J

John Geddes

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
 
D

dhtml

John said:
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
 
J

John Geddes

dhtml said:
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
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 <p> for example.

John Geddes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,250
Latest member
Charlesreero

Latest Threads

Top