SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with Javascript.

    Hi Masters

    I have a problem. That is, i want to set the TOP and LEFT properties of a LAYER <DIV id=win> but something like this.

    If (client_recolution=1024*728)
    {
    #win
    {
    top=200;
    left=50;
    others.....
    }
    }
    else
    #win
    {
    top=300;
    left=50;
    others.....
    }

    please help

  2. #2
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any one please help

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <script>
    function divPosition() {
    if(window.width + window.height == 1752) {
      document.getElementById('win1').style.top = "200";
      document.getElementById('win1').style.left = "50";
    } else {
      document.getElementById('win1').style.top = "300";
      document.getElementById('win1').style.left = "50";
    }
    }
    </script>
    
    <div id="win1">
    Test Div.
    </div>
    
    <a href="#" onClick="divPosition()">Change Div Position</a>
    --try this then change it to an onLoad instead of onClick if it works.

    Code:
    <body onLoad="divPosition()">
    
    <div id="win1">
    Test Div.
    </div>
    
    </body>
    Right now I am unsure about if(window.width + window.height == 1752) being proper code.
    Last edited by Leoj00; Mar 14, 2007 at 21:14.

  4. #4
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Updated and seems to be working:
    Code:
    <script>
    function divPosition() {
    var w = window.screen.width;
    var h = window.screen.height;
    if(w != 1024 && h != 728) {
      document.getElementById('win1').style.top = "300";
      document.getElementById('win1').style.left = "50";
    } else {
      document.getElementById('win1').style.top = "200";
      document.getElementById('win1').style.left = "50";
    }
    }
    </script>
    
    <div id="win1" style="position: absolute">
    Test Div.
    </div>
    
    <a href="#" onClick="divPosition()">Change Div Position</a>
    Code:
    <body onLoad="divPosition()">
    <div id="win1" style="position: absolute">
    Test Div.
    </div>
    </body>
    are you sure you dont want it to be like between W and W && H and H? i am not sure too many user screens will be exactly 1024*728... if they have a screen at 1025*727 the script will execute the else...

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This seems to be working very well:

    Code:
    <script>
    function divPosition() {
    var w = window.innerWidth;
    var h = window.innerHeight;
    if(w != 1024 && h != 728) {
      document.getElementById('win1').style.top = "300";
      document.getElementById('win1').style.left = "50";
    } else {
      document.getElementById('win1').style.top = "200";
      document.getElementById('win1').style.left = "50";
    }
    }
    </script>
    
    <body onLoad="divPosition()">
    
    <div id="win1" style="position: absolute">
    Test Div.
    </div>
    
    <a href="#" onClick="divPosition()">Change Div Position</a>
    
    </body>
    Look here to better understand height and width: http://www.howtocreate.co.uk/tutoria.../browserwindow

  6. #6
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a lot dear.

    This will definately help me.

    Regars and 1,000,000.00 THANKS to YOu.


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
  •