SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: scrollTop

Hybrid View

  1. #1
    SitePoint Evangelist FCC's Avatar
    Join Date
    May 2006
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    scrollTop

    Hi,

    I feel like an idiot, but I can't seem to figure out how to use this property. From my understanding the scrollTop property is supposed to return an integer representing how far the object has been scrolled from the top of the window?

    Here is my code:

    Code:
    <html>
    <body>
        
           fsdfsd
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
    
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
            <div style="height: 100px; width: 100px; overflow: scroll;" onclick="alert(this.scrollTop)">
                0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
            </div>      
            <br />
            <br />
            <br />
            <br />    
    
    </body>
    </html>

    yeah not the most compliant code, but I was just testing it...but anyways, no matter what happens the scrollTop property always returns 0. I don't understand why.

    Any help would be appreciated.

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Put more content in the <div>, since you are referring to the <div>'s scrollTop property.

    Not including the doctype can cause things to act differently, especially in IE. You should always use valid code for testing things.
    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.

  3. #3
    SitePoint Evangelist FCC's Avatar
    Join Date
    May 2006
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for pointing out what was wrong.

    The reason I am doing this is because I have an iframe which has an anchor link in it, and when the link is clicked the causes BOTH the iframe AND parent page to scroll to the top link. And I wanted to like make it so that the parent page then scrolls back to its original position.

    Do you have any idea how I could tackle this?

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perhaps you should try fixing the cause instead of the symptom.

    Is the link something like this?
    Code:
    <a href="#" onclick="doSomething();">do something</a>
    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.

  5. #5
    SitePoint Evangelist FCC's Avatar
    Join Date
    May 2006
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm...the problem is I don't have control of the website inside of the iFrame...

    So whatever the anchor link does is out of my control. I've been trying to find a way around this.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •