/    Sign up×
Community /Pin to ProfileBookmark

I need to know how to get the property of the window that tells me where it currently is scrolled to. That way I can set the top and left a of div tag so it is always visible.

If I can just get the value of the windows (frames) position after scrolling I would be happy

document.body.offsetleft always returns 0

although
document.body.offsetHeight does return the proper value.

What am I missing?

IE5.5

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@FangJan 05.2004 — This gives the offsets:
// Scroll offset:
if (window.pageYOffset)
Ypos=window.pageYOffset;
else if (document.documentElement && document.documentElement.scrollTop)
Ypos=document.documentElement.scrollTop;
else if (document.body)
Ypos=document.body.scrollTop;

if (window.pageXOffset)
Xpos=window.pageXOffset;
else if (document.documentElement && document.documentElement.scrollLeft)
Xpos=document.documentElement.scrollLeft;
else if (document.body)
Xpos=document.body.scrollLeft;

window.status=Xpos+":"+Ypos;
Copy linkTweet thisAlerts:
@danscanauthorJan 05.2004 — Thanks it Worked Great.

Any tips on making it fire this function on the user scrolling?

I will try to find answer on my own but if your not busy.
Copy linkTweet thisAlerts:
@FangJan 05.2004 — IE has a window "onscroll" event
Copy linkTweet thisAlerts:
@fredmvJan 06.2004 — [i]Originally posted by Fang [/i]

[B]IE has a window "onscroll" event [/B][/QUOTE]
Mozilla does as well.
×

Success!

Help @danscan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...