SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Hybrid View
-
Jul 3, 2007, 05:28 #1
- Join Date
- Feb 2007
- Posts
- 42
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Controlling visibility via scrolling
I have a table full of inputs and there are times when I want to set the focus to a specific input but if the table is large enough or the window is small enough, the input may be scrolled out of view. I know I can do inputElement.focus() to put the input cursor in the element but can I determine if the element is in the view and force the window to scroll so that it is?
-
Jul 3, 2007, 06:11 #2
- Join Date
- Nov 2005
- Location
- The Netherlands
- Posts
- 808
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If your elements contain ids, you can simply add a hash to the current URL, like this:
Code javascript:window.location.hash = "myId";
The URL now looks like "www.yourdomain.com/#myId", and will automatically scroll to the element with id "myId".
-
Jul 3, 2007, 07:39 #3
- Join Date
- Feb 2007
- Posts
- 42
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks but...
... I'd rather not change the URL that shows up in the address bar or that's used when the user reloads the page.
-
Jul 3, 2007, 15:38 #4
- Join Date
- Mar 2005
- Location
- USA
- Posts
- 5,482
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Don't browsers automatically scroll down if you give focus to a form control?
You can use scrollIntoView(), which seems to be supported by IE5+/Win, Firefox, Netscape 7.0+, Opera 9+, and Safari 2+.We miss you, Dan Schulz.
Learn CSS. | X/HTML Validator | CSS validator
Dynamic Site Solutions
Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.
-
Jul 4, 2007, 05:35 #5
- Join Date
- Feb 2007
- Posts
- 42
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
At least not Firefox 2.x.
You can use scrollIntoView(), which seems to be supported by IE5+/Win, Firefox, Netscape 7.0+, Opera 9+, and Safari 2+.
-
Jul 6, 2007, 05:15 #6
- Join Date
- Feb 2007
- Posts
- 42
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks
scrollIntoView() was just the thing.
Bookmarks