| |

VerySource

 Forgot password?
 Register
Search
View: 38|Reply: 5

How to change the position of
according to the screen resolution?

[Copy link]

1

Threads

2

Posts

3

Credits

Newbie

Rank: 1

Credits
3

 China

Post time: 2020-3-1 11:30:01
| Show all posts |Read mode
I used the code of a floating window on the webpage.
When I adjusted the screen resolution to 1280 * 1024. It won't work. . Blocking the logo above.
I use
  if (window.screen.width == 1280)
   {
    document.write "<div id = 'topview' style = 'position: absolute; margin-left: -845px; width: 145px; top: 0px; z-index: 1;'>";
   }
  else
  {
    document.write "<div id = 'topview' style = 'position: absolute; margin-left: -1025px; width: 145px; top: 0px; z-index: 1;'>";
  }
This statement controls the position of the <div>. .
But it cannot be achieved. . .
js is not too familiar. . Is it a problem with the code? Or something else?
Reply

Use magic Report

0

Threads

4

Posts

5

Credits

Newbie

Rank: 1

Credits
5

 China

Post time: 2020-5-26 07:00:01
| Show all posts
When you change the screen resolution, things on the webpage are not refreshed

I suggest you make the above code into a function
Use window.setInterval ("function to be called", 500) to call regularly
Reply

Use magic Report

1

Threads

2

Posts

3

Credits

Newbie

Rank: 1

Credits
3

 China

 Author| Post time: 2020-5-30 13:45:01
| Show all posts
Thanks for the reminder upstairs .. but the question is:
My code has a script error ... don't know why ...?
I haven't found anything wrong after searching for a long time ... but ...
Reply

Use magic Report

0

Threads

7

Posts

7

Credits

Newbie

Rank: 1

Credits
7

 China

Post time: 2020-6-4 01:15:02
| Show all posts
<table style='border:1px solid #000; width: 100px; height: 200px;' align=right>
<tr><td>sdafsadf</td></tr></table>

Set near right margin
Reply

Use magic Report

0

Threads

7

Posts

7

Credits

Newbie

Rank: 1

Credits
7

 China

Post time: 2020-6-10 13:15:01
| Show all posts
<div style='border:1px solid #000; width: 100px; height: 200px; position:absolute;right:1px'>sdafsadf</div>
Reply

Use magic Report

0

Threads

13

Posts

13

Credits

Newbie

Rank: 1

Credits
13

 China

Post time: 2020-6-20 19:30:01
| Show all posts
Use relative position, just position it relative to your logo.

code show as below:

function GetRelated(element,attribute)
{
The
    if (arguments.length != 2 || element == null)
    {
        return null;
    }

    var elmt = element;

    var offsetTop = elmt.offsetTop;

var offsetLeft = elmt.offsetLeft;
The
    while( elmt.offsetParent) {

elmt = elmt.offsetParent

        offsetTop += elmt.offsetTop;

offsetLeft += elmt.offsetLeft;

    }

if( attribute =='top') return offsetTop;

else if( attribute =='left') return offsetLeft;

else return 0;

}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2020|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list