Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [html] dopasowanie strony do ekranu
KeramxD
post 29.08.2014, 16:42:03
Post #1





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 8.09.2013

Ostrzeżenie: (0%)
-----


Witam, stworzyłem ułatwienie które mam zamiar używać na ios w przeglądarce. Obraz jest bardzo duży a chciałbym aby sie dopasowywal.

<html>
<table border="0" cellspacing="0" cellpadding="0">
<td>
<a href="http://grzegorz-zurek.asuscomm.com:8081/downloadmaster/index.asp"><img src="http://i.imgur.com/h8ZWGNh.jpg" alt="" /></a>
</td>
<td>
<a href="http://grzegorz-zurek.asuscomm.com"><img src="http://i.imgur.com/eb1eMU0.jpg" alt="" /></a>
</td>
</tr>
</table>
Go to the top of the page
+Quote Post
2 Stron V   1 2 >  
Start new topic
Odpowiedzi (1 - 19)
tomi1985
post 29.08.2014, 17:50:07
Post #2





Grupa: Zarejestrowani
Postów: 192
Pomógł: 12
Dołączył: 23.09.2010
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


  1. <table style="width:100%;height:100%">
  2. ...



powinno zadziałać

Ten post edytował tomi1985 29.08.2014, 17:50:40
Go to the top of the page
+Quote Post
KeramxD
post 29.08.2014, 18:54:04
Post #3





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 8.09.2013

Ostrzeżenie: (0%)
-----


Nie działa.


Adres strony:
router.zurek.co
Go to the top of the page
+Quote Post
tomi1985
post 29.08.2014, 19:49:48
Post #4





Grupa: Zarejestrowani
Postów: 192
Pomógł: 12
Dołączył: 23.09.2010
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


ponieważ kolego masz tam 2 duże obrazki które trzeba skompresować do rozmiaru przegladarki...

Najprostrzym rozwiązaniem "według mnie" będzie pobranie rozdzielczości ekranu za pomocą js, następnie od wartości szerokości odjąć Twój margines pomiędzy obrazkami, po czym podzielić tą wartość na pół i masz tu szerokość obrazka.

To wklej w nagłówku lub w pliku css
  1. body {
  2. margin:0;
  3. padding:0;
  4. text-align:center;
  5. }


a to na samym dole stronki i dodaj id obrazków które chcesz przeskalować
  1. <script type="text/javascript">
  2. var szer = screen.width/2;
  3. var wys = window.innerHeight - 5;
  4.  
  5. document.getElementById("one").width = szer;
  6. document.getElementById("one").height = wys;
  7.  
  8. document.getElementById("two").width = szer;
  9. document.getElementById("two").height = wys;


Ten post edytował tomi1985 29.08.2014, 19:58:56
Go to the top of the page
+Quote Post
trueblue
post 29.08.2014, 19:51:59
Post #5





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


  1. img{
  2. max-width:100%;
  3. height:auto;
  4. }


--------------------
Go to the top of the page
+Quote Post
KeramxD
post 29.08.2014, 20:00:50
Post #6





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 8.09.2013

Ostrzeżenie: (0%)
-----


Nie rozumiem.
Mógłbyś mi to wkleić do tego kodu co podałem? Byłbym bardzo wdzięczny.
Go to the top of the page
+Quote Post
tomi1985
post 29.08.2014, 20:04:06
Post #7





Grupa: Zarejestrowani
Postów: 192
Pomógł: 12
Dołączył: 23.09.2010
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


  1. max--width:100%


i w jaki sposób to ma mu pomóc ?

a to w nagłówku strony "po znaczniku html" wink.gif
  1. body {
  2. margin:0;
  3. padding:0;
  4. text-align:center;
  5. }
  6.  
  7.  
  8.  
  9.  
  10. </head>


  1. table id="demo" border="0" cellspacing="0" cellpadding="0" style="width:100%;height:100%">
  2. <td>
  3. <a href="http://grzegorz-zurek.asuscomm.com:8081/downloadmaster/index.asp"><img id="one" src="http://i.imgur.com/h8ZWGNh.jpg" alt="" /></a>
  4. </td>
  5. <td>
  6. <a href="http://grzegorz-zurek.asuscomm.com"><img id="two" src="http://i.imgur.com/eb1eMU0.jpg" alt="" /></a>
  7. </td>
  8. </tr>
  9.  
  10. <script type="text/javascript">
  11. var szer = screen.width/2;
  12. var wys = window.innerHeight - 5;
  13.  
  14. document.getElementById("one").width = szer;
  15. document.getElementById("one").height = wys;
  16.  
  17. document.getElementById("two").width = szer;
  18. document.getElementById("two").height = wys;


Można jeszcze użyć

  1. document.getElementsByTagName('img')


dla wszystkich zdjęć, wówczas zaoszczędzić można w tym wypadku 2 linijki kodu wink.gif

Ten post edytował tomi1985 29.08.2014, 20:08:49
Go to the top of the page
+Quote Post
KeramxD
post 29.08.2014, 20:08:10
Post #8





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 8.09.2013

Ostrzeżenie: (0%)
-----


Dobra, ale zobacz co się teraz stało. Obrazki schowały się pod siebie, a chodzi o to żeby były koło siebie.
Go to the top of the page
+Quote Post
KeramxD
post 29.08.2014, 20:08:15
Post #9





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 8.09.2013

Ostrzeżenie: (0%)
-----


Dobra, ale zobacz co się teraz stało. Obrazki schowały się pod siebie, a chodzi o to żeby były koło siebie.
Go to the top of the page
+Quote Post
tomi1985
post 29.08.2014, 20:11:13
Post #10





Grupa: Zarejestrowani
Postów: 192
Pomógł: 12
Dołączył: 23.09.2010
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


nie możliwe kolego ponieważ skopiowałem całą Twoją stronę i sprawdziłem u siebie wink.gif

masz tu cały kodzik swojej strony + modyfikacja kompresji zdjęć

  1. <!doctype html>
  2. body {
  3. margin:0;
  4. padding:0;
  5. text-align:center;
  6. }
  7.  
  8.  
  9. </head>
  10.  
  11. <table id="demo" border="0" cellspacing="0" cellpadding="0" style="width:100%;height:100%">
  12. <td>
  13. <a href="http://grzegorz-zurek.asuscomm.com:8081/downloadmaster/index.asp"><img id="one" src="http://i.imgur.com/h8ZWGNh.jpg" alt="" /></a>
  14. </td>
  15. <td>
  16. <a href="http://grzegorz-zurek.asuscomm.com"><img id="two" src="http://i.imgur.com/eb1eMU0.jpg" alt="" /></a>
  17. </td>
  18. </tr>
  19.  
  20.  
  21. <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
  22. <!-- Apple Touch Icons -->
  23. <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
  24. <link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png" />
  25. <link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png" />
  26. <link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png" />
  27. <link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144x144.png" />
  28. <link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-60x60.png" />
  29. <link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-120x120.png" />
  30. <link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-76x76.png" />
  31. <link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-152x152.png" />
  32. <!-- Windows 8 Tile Icons -->
  33. <meta name="msapplication-square70x70logo" content="smalltile.png" />
  34. <meta name="msapplication-square150x150logo" content="mediumtile.png" />
  35. <meta name="msapplication-wide310x150logo" content="widetile.png" />
  36. <meta name="msapplication-square310x310logo" content="largetile.png" />
  37. <script type="text/javascript">
  38. var szer = screen.width/2;
  39. var wys = window.innerHeight - 5;
  40.  
  41. document.getElementById("one").width = szer;
  42. document.getElementById("one").height = wys;
  43.  
  44. document.getElementById("two").width = szer;
  45. document.getElementById("two").height = wys;
  46. </body>
  47.  
  48. </html>


Ten post edytował tomi1985 29.08.2014, 20:32:31
Go to the top of the page
+Quote Post
KeramxD
post 29.08.2014, 20:15:20
Post #11





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 8.09.2013

Ostrzeżenie: (0%)
-----


Działa, wielkie dzięki. Trochę rozciąga, ale to już wina wymiarów grafiki.
Go to the top of the page
+Quote Post
tomi1985
post 29.08.2014, 20:16:47
Post #12





Grupa: Zarejestrowani
Postów: 192
Pomógł: 12
Dołączył: 23.09.2010
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


zawsze mozna jakies proporcje ustawić jak chcesz wink.gif i będzie git ale wówczas nie będzie w 100 % na całej stronie
Go to the top of the page
+Quote Post
KeramxD
post 29.08.2014, 20:19:20
Post #13





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 8.09.2013

Ostrzeżenie: (0%)
-----


Ale telefon trochę świruje:

Go to the top of the page
+Quote Post
tomi1985
post 29.08.2014, 20:30:39
Post #14





Grupa: Zarejestrowani
Postów: 192
Pomógł: 12
Dołączył: 23.09.2010
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Podmień

  1. var szer = screen.width/2;
  2. var wys = window.innerHeight - 5;


na

  1. var ratio = window.devicePixelRatio || 1;
  2.  
  3. var szer = (screen.width*ratio)/2 - 0;
  4. var wys = (window.innerHeight*ratio) - 5;


i daj znać
Go to the top of the page
+Quote Post
KeramxD
post 29.08.2014, 20:40:48
Post #15





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 8.09.2013

Ostrzeżenie: (0%)
-----


Na telefonie to samo, natomiast na komputerze zmieniło się przesunięcie.
Go to the top of the page
+Quote Post
tomi1985
post 29.08.2014, 20:45:37
Post #16





Grupa: Zarejestrowani
Postów: 192
Pomógł: 12
Dołączył: 23.09.2010
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


hmmm dziwne ponieważ na ipadzie jest już idealnie... ale na iphonie faktycznie lipa nadal ....

podmień to na to

  1. var szer = document.documentElement.clientWidth/2 ;
  2. var wys = document.documentElement.clientHeight - 5;
Go to the top of the page
+Quote Post
KeramxD
post 29.08.2014, 20:48:50
Post #17





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 8.09.2013

Ostrzeżenie: (0%)
-----


U mnie na na iPadzie też idealnie.

Śmiga, więlkie dzięki. A co gdybym w przyszłości chciał np dodać kolejną ikonkę? (3 fragment obrazka). Dodam kolejną tabelę z odnośnikiem a w skrypcie będę musiał coś mieszać?
Go to the top of the page
+Quote Post
tomi1985
post 29.08.2014, 20:50:58
Post #18





Grupa: Zarejestrowani
Postów: 192
Pomógł: 12
Dołączył: 23.09.2010
Skąd: Warszawa

Ostrzeżenie: (0%)
-----




musiałbyś to podzielić przez 3 wink.gif to raz a dwa to dodać kolejne id

czyli np.

  1. document.getElementById("three").width = szer;
  2. document.getElementById("three").height = wys;


Ten post edytował tomi1985 29.08.2014, 20:57:46
Go to the top of the page
+Quote Post
trueblue
post 29.08.2014, 21:12:18
Post #19





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Cytat(tomi1985 @ 29.08.2014, 21:04:06 ) *
  1. max--width:100%

Na pewno -- nie pomoże.
Ale widzę, że wolicie zamęczać stronę kodem JS, niż zapoznać się z podstawami wprowadzania responsywności do strony.


--------------------
Go to the top of the page
+Quote Post
tomi1985
post 29.08.2014, 21:20:40
Post #20





Grupa: Zarejestrowani
Postów: 192
Pomógł: 12
Dołączył: 23.09.2010
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


łał ... literówka....

to sobie sprawdź czy to co podałeś pomoże aby zdjęcia zawsze były na całym oknie

gdzie np. zdjecie ma 2500x1500 x2 zdjęcia

a rozdzielczość ekranu np. 800x600

powodzenia wink.gif
Go to the top of the page
+Quote Post

2 Stron V   1 2 >
Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 15:41