"IsInview" function?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Geddes

    "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
  • dhtml

    #2
    Re: "IsInview& quot; function?

    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 'scrollIntoView IfNeeded' (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

    Comment

    • John Geddes

      #3
      Re: "IsInview& quot; function?

      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 'scrollIntoView IfNeeded' (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

      Comment

      Working...