What unit of measurement is involved here?

Posted on 2006-03-19
Last Modified: 2013-11-15 2003

I am using  x= IE.Document.documentElement.scrollTop

What unit of measurement does x represent and how do I convert that into something that equals pixels?

 if I move the scrollbar down 1 pixel x = 2
 if I move the scrollbar down 2 pixels x = 5
 if I move the scrollbar down 3 pixels x = 7
 if I move the scrollbar down 10 pixels x = 24


Question by:gosonic
    LVL 84

    Expert Comment

    The units are pixels.  You seem to be moving the scrollbar by two or three pixels at a time.
    LVL 48

    Accepted Solution

    HtmlElement.ScrollTop Property
    The distance, in pixels, between the top edge of the element and the top edge of its content.

    How can this happen? We can only guess. Possibly Explorer manages scrollbar state using float or double variables, and converts them to integer before setting actual scrollbar position.
    Suppose that full  document range is 12.0, and one step is 1.2 - this is calculated by Explorer using some criterions. In this case, when user scrolls page, internal counter changes by the following way:
    0  1.2  2.4  3.6  4.8   ...

    Actual  scrollbar position in pixels is:

    0   1     2     4     5   ...

    Author Comment

    ozo - I double checked. Only 1 pixel at a time.

    I agree that seems to be the case.  To add to the problem when I change monitors x changes also.
    Example on a 17 inch display a 100 pixel movement sets x to 229  on a 19 inch display a 100 pixel movement sets x to 293.  Both set at (1024x768)  Go figure, you would think there would be something useful here with IE.Document.documentElement.scrollTop. but I can't find it, yet.  
    LVL 48

    Expert Comment

    Many graphics programs work with images using their actual size in mm, inches etc. In .NET you can see Graphics.DpiX and Graphics.DpiY properties. IE doesn't use it but it uses unmanaged API which does the same. Now suppose you have some image whith known pixel size (for example, 1 pixel = 1 mm), and you want to draw it with it's actual size. This is the place for floating-point calculations and setting scroll range. The same may apply to fonts - let's say you want to draw text with 2 mm height on any monitor with any screen resolution.

    Author Comment

    I gave the Graphics.DpiX a try and can't find any relief there either. Thanks for all you insight, I going to go to work on a work around - thanks again.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Suggested Solutions

    I previously wrote an article addressing the use of UBCD4WIN and SARDU. All are great, but I have always been an advocate of SARDU. Recently it was suggested that I go back and take a look at Easy2Boot in comparison.
    When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now