Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2009
    Location
    Earth - sometimes sky :-)
    Posts
    121
    Thanks
    51
    Thanked 2 Times in 2 Posts

    how to positioning the scrollbar?

    So, here is my question:

    Is there some possibility with php to put the horizontal scroll bar of the web browser into the center if the "width" of web page are bigger then the "width" of the web browser screen?

    So I don't need to scroll to right if I open the page, but the horizontal scroll bar will be positioned in the center.

    That code should do the same think like I when I take the scroll bar and put it in the center position, but this should be happen when I load the page automatically.

    Or how can I do that?

    thanks to all . . .

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by joda View Post
    So, here is my question:

    Is there some possibility with php to put the horizontal scroll bar of the web browser into the center if the "width" of web page are bigger then the "width" of the web browser screen?

    So I don't need to scroll to right if I open the page, but the horizontal scroll bar will be positioned in the center.

    That code should do the same think like I when I take the scroll bar and put it in the center position, but this should be happen when I load the page automatically.

    Or how can I do that?

    thanks to all . . .
    no, php is server side. Is same thing like using html/css but generated when user ask for a page. As I said, javascript or other client side language.

    best regards

  • Users who have thanked oesxyl for this post:

    joda (11-06-2009)

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Moved from PHP to the Javascript forum.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    joda (11-06-2009)

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Code:
    /* -*- c++ -*- */
    function centerdoc(){
      var off;
      // Firefox/Opera/Safari but not IE
      off = (document.body.clientWidth - window.innerWidth)/2 - window.pageXOffset;
      window.scrollTo(off,0);
    };
    
    window.onload = centerdoc;
    this will work in Firefox( tested), Opera and Safari (both not tested) but somebody else must solve the problem for IE along with some browser detect code to control the flow.

    best regards
    Last edited by oesxyl; 11-06-2009 at 06:42 PM.

  • #5
    WA
    WA is offline
    Administrator
    Join Date
    Mar 2002
    Posts
    2,596
    Thanks
    2
    Thanked 19 Times in 18 Posts
    Closing thread, as cross posted. Please continue any discussion in the original thread: http://www.codingforums.com/showthread.php?t=181385
    - George
    - JavaScript Kit- JavaScript tutorials and 400+ scripts!
    - JavaScript Reference- JavaScript reference you can relate to.


  •  

    Posting Permissions

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