473,406 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to center an scrolled-to anchor???

Elisabeth Dietz
Hello there,

at the moment I am more than stucked while trying to scroll to an anchor in center of screen. I´ve tried using Ariel Flesler´s Local Scroll, which works perfectly for scrolling an anchor to the top left or any hash given position / offset etc.
But now that I try to locate the anchor in the middle of the screen, depending on the screen size I am at the end of my knowledge though searching the web for days now...

My first idea was to put something like this to the code but this dosn't work.
I think that I just don´t know the right position to put it in (I tried it several times)?!

Expand|Select|Wrap|Line Numbers
  1. var topOffset = 0 - Math.round( $(window).height() / 2 );
  2. var leftOffset = 0 - Math.round( $(window).width() / 2 );
  3. var topTargetOffset = $(this.hash).offset().top - topOffset; 
  4. var leftTargetOffset = $(this.hash).offset().left - leftOffset; 
  5.  
the call for the script is

Expand|Select|Wrap|Line Numbers
  1. $.localScroll({
  2. axis:'xy',
  3. queue:false,
  4. duration:2000,
  5. });
  6.  
and the query for scrollTo and localScroll can be found here:

http://flesler.blogspot.com/2007/10/jquerylocalscroll-10.html
http://flesler.blogspot.com/2007/10/jqueryscrollto.html

I hope the description is comprehensible...

Thanks a lot for any hints or tips!!

Elisabeth
Jun 8 '11 #1
1 2631
hsriat
1,654 Expert 1GB
Try somthing like this:
Expand|Select|Wrap|Line Numbers
  1. $('html,body').animate({ scrollTop: $(this.hash).offset().top - $(window).height() / 2 + $(this.hash).height() / 2}, 2000)
  2.  
ignore $(this.hash).height() part if you don't need the element to be centred.
Jun 13 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Mel | last post by:
is it possible to have URL links inside a list box ? WITHOUT the use of JavaScript? thanks for your help Mel
13
by: MrBaseball34 | last post by:
In this HTML: <html> <head> <title>Page 1</title> </head> <body style="background:#C2BFA5;"> <span style="background-color:#F9DFB2; position: absolute; border:thin inset;
2
by: serge | last post by:
Where can I find this when I install v8.2? Thank you
1
by: Ricardo Luceac | last post by:
Hi... I have a web form that let the user imput some fields.. It is Always a label and a textbox per line... But how can I center these 2 controls in a form so that if the user uses a...
7
by: ALI-R | last post by:
Hi All, I have two user controls (header and footer) ,,which I've placed in an HTML Table in a page.I set the **align="center"** in the table and the table still is on the left side of the page...
11
by: Ben Amada | last post by:
Hello, When centering a block of HTML, in the past, I've always used: <div align="center"> ... </div> However, in VS 2005, I get the following warning: "Validation (XHTML 1.0...
0
by: moustikitos | last post by:
I wrote a scrolled frame for Tkinter : http://bruno.thoorens.free.fr/downloads/scrolled.py I also wrote a Tile wrapper for Python : http://bruno.thoorens.free.fr/downloads/ttk.html...
5
Gregos
by: Gregos | last post by:
Remember I'm new at this... My webpage: http://www.geocities.com/gregos_39/gregos/gregpage.html My code: <html> <head> <title>Gregos Apple/Mac Help Page</title> <link href="home_style.css"...
11
by: Mel | last post by:
Does anyone know a way to center the info. on a webpage? I want my web site to work like MySpace.com where the page content remains centered when I resize the browser window. For the life of me I...
5
iam_clint
by: iam_clint | last post by:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.