Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 1387 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     Javascript :

Load Page at a Certain Position?

Thread title: Load Page at a Certain Position?
Reply    
    Thread tools Search this thread Display Modes  
04-23-2010, 04:37 PM
#1
mattf87 is offline mattf87
Status: I'm new around here
Join date: Mar 2008
Location:
Expertise:
Software:
 
Posts: 8
iTrader: 0 / 0%
 

mattf87 is on a distinguished road

  Old  Load Page at a Certain Position?

Hi everyone,

I was wondering if there was a way to use javascript in order to have the browser load the page at a certain position.

Specifically, I have a div that I want to be perfectly centered in the middle of the user's browser on load. It would have to be centered both on the y axis and x axis (for specific reasons my page is extra tall and extra extra wide).

To be clear, I don't want to change this div's actual position on the page. I want to make it so that the browser window's scrollbars are set so that this div is in the center of the window once the page loads. (Kind of like linking to an anchor tag except I want it to load completely centered instead of top-left.)

If anyone knows of a way to do this or can provide any other input it would be greatly appreciated.

Thanks!

Reply With Quote
04-23-2010, 05:57 PM
#2
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

Sure, there are properties belonging to the window and the div that you can take a look at, do a little math and change to the correct values. Things to look into would be element.scrollTop (and …scrollLeft) to manipulate the scrollbars, element.offsetTop (and …offsetLeft) to help with finding the top-left corner of your div, element.offsetWidth (and offsetHeight).

Also if you have the luxury of working with a JavaScript framework (like jQuery, Prototype, YUI, etc.) then things like this are usually wrapped up in helper functions to make life easier.

Reply With Quote
05-14-2010, 12:03 PM
#3
c69 is offline c69
c69's Avatar
Status: Junior Member
Join date: Nov 2009
Location: Kiev, Ukraine
Expertise:
Software:
 
Posts: 27
iTrader: 0 / 0%
 

c69 is on a distinguished road

  Old

or use links like - page.html#Section

Reply With Quote
Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed