| Blockbuster sites, amazing reunions

Share Tips

New Topic Subscription Options  

How to get window.pageYOffset value

Forums: Questions and Answers About Building Your Site
Created on: 04/21/11 10:24 PM Views: 2250 Replies: 12
Thursday, April 21, 2011 at 10:24 PM

I posted a detailed explanation that obtaining window.pageYOffset value fails - it's always 0 - and how it's related to the jquery IM code module yesterday. Code works outside of CC or by disabling a few IM code calls.

Today it's nowhere to be found. There's also no message anywhere else. If it's moved as before, please let me know so I can get a resolution to this.

I'm thinking your code /jquery is binding to the scroll event thus document values never get updated. If the code updates the window.pageYoffset/pageXoffset values (vary per browser), it would give me access so I can properly center an image.

Friday, April 22, 2011 at 11:52 AM - Response #1

I searched around as well and the only other forum post I found from you in the past couple days is the following click here

Friday, April 22, 2011 at 11:53 AM - Response #2

Jack, I have searched the forums as well and the only other one I found

Friday, April 22, 2011 at 1:19 PM - Response #3

Yep, it's gone- posted same time as the other one. Could be the Amazon cloud problem that day? Things were doggone slow.

But that's whatever it was. I'm really interested in solving getting scroll offset values. The module that triggers (suppresses) the scroll values is im_20110222.js

IOW, if I remove that module my code works or if I edit the module and remove these 3 lines

jQuery( "html,body").addClass("im_body"); // disable 1
jQuery( "#main_container").addClass("main_container"); // disable 2
jQuery("#main_container").css("overflow-x", "auto"); // disable 3

I have to disable all 3, leaving just 1 of them active disables the ability to get scroll values.

Tuesday, April 26, 2011 at 1:10 AM - Response #4

Bump - is this fixable? I've also now run into a 2nd problem that is very similar - I can't install a mouse handler.

These sort of constraints severely limit creativity and require some workaround hooks to be available.

Thursday, August 11, 2011 at 1:17 PM - Response #5

The pageYOffset attribute works in Firefox, but not in Explorer (at least through version 8 ).
Here is a javascript function to select the right attribute and correctly return the value you're looking for:

Thursday, August 11, 2011 at 2:28 PM - Response #6

That's the code I used. As I recall, that code works outside of CC but not inside of CC pages. The problem is in the jquery code somewhere as noted above. Disabling the jQuery code makes it work as it is supposed to work.

However, there is a another method that relies on a specific div that I think is in all CC pages. Plus works in ALL the browsers. I sort of put this on the back-burner as a tool I can use.

Edited 08/11/11 2:30 PM
Thursday, August 11, 2011 at 3:59 PM - Response #7

In order to test the function, I loaded a classcreator site in Internet Explorer, scrolled the page a little bit, and typed into the address bar "javascript:alert(document.documentElement.scrollTop)"

The browser reported a number, as expected.

Can you provide further information about how you are trying to get and use the window scroll position?

Thursday, August 11, 2011 at 6:51 PM - Response #8

I have various test pages, but this is an old one that works OUTSIDE of CC but not inside of CC (has a bunch of test junk left in it, but I just left it there)

Just click on the image. On tab it gives both offsets.

Now copy that code into a "clean" page and load with Firefox. You'll see that it gives both left and top offsets. Yet inside of CC it is always 0.

I think it works in all the browsers, except IE - as a standalone page. But I solved all that using a different approach.

Edited 08/11/11 6:52 PM
Friday, August 12, 2011 at 11:15 AM - Response #9

I noticed your alert was reporting an unset property: alert(window.scrollY). I commented out the alert and added alert(position.join(',')) which is the array value your code is populating, shown as a string value.

Friday, August 12, 2011 at 12:41 PM - Response #10

That was a left over from various iterations of this code. I was looking at was document.title

But with that change it now works for ALL the browsers inside and outside of CC, including IE 9 (you can check IE8 or I can later).

So I hope you got something out of this too.

Now why would your fix make a difference? I can see the issue for IE (it probably stopped the script), but why did Firefox work standalone?

THANK YOU for looking Eric. I assumed that I all I needed to look at was the title output and ignored the error when I saw it come up in IE, obviously that was a mistake.Twisted Evil

P.S. So the other code I finally got working, worked because it didn't have that mistake, not that I targeted a "div".

(Now to get mouse working someday. I'm tied up with for a bit, but hopefully you can spot a mistake there also. I was going to use it mainly for occasional cursor fun.)

Edited 08/12/11 12:44 PM
Friday, August 12, 2011 at 12:58 PM - Response #11

The difference is that in the tab label, you were explicitly referencing the values contained in the array ( position[0] and position[1] ), while in the alert you were trying to display the array itself, and the result would vary depending on the browser. The code I inserted replaces the array object with a call to an internally defined function which returns the values contained in the array.

Anyway, I am sorry it took so long to get this resolved, and I hope it helps!

I'm not sure what your final parenthetical refers to, but if you run into trouble again, we'll be happy to assist.

Friday, August 12, 2011 at 4:00 PM - Response #12

My mistake was that I didn't care about the "alert" per se. It was just there as a "left over". But that apparently WAS the problem.

Still do not understand why the original failed inside of CC vs working outside of CC. That's really what made me just give up on that version.

Installing a mouse driver had similar issues - outside of CC it worked fine. Inside of CC it did not.

When I get back to the mouse thing, I'll post what doesn't work. It's more a fun message thing - you may have seen some examples.

Again, Thanks for the help

New Topic  
Subscription Options: Have all new forum posts sent directly to your email.
Subscription options are available after you log in.