Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Dodawanie do marginLeft i marginTop
-arrtxp-
post
Post #1





Goście







MAM TAKIE COŚ
chciałem zrobić aby mi dodawało do margin liczbę 32 lecz nie wychodzi wie ktoś może czemu?
o to kawałek kodu, który za to odpowiada tongue.gif

  1. var ruch = 0;
  2. var topMargin = document.getElementById('map').style.marginTop;
  3. var leftMargin = document.getElementById('map').style.marginLeft;
  4. var pole = "32";
  5. function Move_map(x, y, licz) {
  6. if(isNaN(parseInt(licz))) { if(ruch > 0) return;
  7. window.frames['view_info'].location= "poruszanie.php?x=" + x + "&y=" + y + "";
  8. licz = 0;
  9. }
  10. ruch = 1;
  11. document.getElementById('map').style.marginTop = topMargin+pole;
  12. document.getElementById('map').style.marginLeft = leftMargin+pole;
  13. if(licz < 33) {
  14. licz++;
  15. setTimeout("Move_map(" + x + ", " + y + ", " + licz + ")", 15);
  16. }
  17. else ruch = 2;
  18. }


Ten post edytował arrtxp 15.01.2010, 12:17:04
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 5)
trucksweb
post
Post #2





Grupa: Zarejestrowani
Postów: 1 199
Pomógł: 31
Dołączył: 22.03.2004
Skąd: Warszawa

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


wedlug mnie musisz ustalic typ danych na int za pomoca parseInt()


--------------------
Rozmawia dwóch dyrektorów:
- Jaki jest twój ideał sekretarki?
- 20-letnia dziewczyna z 30-letnim doświadczeniem.
Go to the top of the page
+Quote Post
skowron-line
post
Post #3





Grupa: Zarejestrowani
Postów: 4 340
Pomógł: 542
Dołączył: 15.01.2006
Skąd: Olsztyn/Warszawa

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


Cytat(trucksweb @ 15.01.2010, 12:59:55 ) *
wedlug mnie musisz ustalic typ danych na int za pomoca parseInt()


Musi i to napewno w przeciwnym wypadku + połączy mu ciągi.


--------------------
I'm so fast that last night I turned off the light switch in my hotel room and was in bed before the room was dark - Muhammad Ali.
Peg jeżeli chcesz uprawiać sex to dzieci muszą wyjść, a jeżeli chcesz żeby był dobry ty też musisz wyjść - Al Bundy.

QueryBuilder, Mootools.net, bbcradio1::MistaJam
http://www.phpbench.com/
Go to the top of the page
+Quote Post
-arrtxp-
post
Post #4





Goście







Zrobiłem tak i dalej nie ogarnia
  1. var topMargin = parseInt(document.getElementById('mapimg').style.marginTop);
  2. var leftMargin = parseInt(document.getElementById('mapimg').style.marginLeft);
  3. var pole = "32";
  4. function Move_map(x, y, licz) {
  5. if(isNaN(parseInt(licz))) { if(ruch > 0) return;
  6. window.frames['view_info'].location= "poruszanie.php?x=" + x + "&y=" + y + "";
  7. licz = 0;
  8. }
  9. ruch = 1;
  10. document.getElementById('mapimg').style.marginTop = topMargin+pole;
  11. document.getElementById('mapimg').style.marginLeft = leftMargin+pole;
  12. if(licz < 33) {
  13. licz++;
  14. setTimeout("Move_map(" + x + ", " + y + ", " + licz + ")", 15);
  15. }
  16. else ruch = 2;
  17. }


Go to the top of the page
+Quote Post
mls
post
Post #5





Grupa: Zarejestrowani
Postów: 677
Pomógł: 89
Dołączył: 31.08.2003
Skąd: Warszawa

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


Może po prostu czytaj ze zrozumieniem odpowiedzi, i zmień
Kod
var pole = "32";

na
Kod
var pole = 32;


--------------------
Go to the top of the page
+Quote Post
kamil4u
post
Post #6





Grupa: Zarejestrowani
Postów: 2 350
Pomógł: 512
Dołączył: 4.01.2009
Skąd: Wrocław / Świdnica

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


Poza tym brakuje jednostki, czyli 'px' prawdopodobnie. Musisz też zamienić topMargin na liczbę, bo prawdopodobnie masz ją w formie tekstu - "XXpx", gdzie XX to jakaś liczba.
Kod
<input type="button" value="dodaj do margin-top  10px;" onClick="dodaj(10);">

<div style="margin-top: 10px;" id="test">test</div>

<script>
function dodaj(value){
  var el = document.getElementById('test');
  var marginTop = parseInt(el.style.marginTop);
  el.style.marginTop = value+marginTop+'px'
}
</script>


--------------------
Go to the top of the page
+Quote Post

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 Aktualny czas: 20.08.2025 - 11:29