Hey all. It's been a while since I last visited.
Short description of program: Board game which's html elements are fully constructed using DHTML/Javascript. Board is constructed of html table, and each table cell has one image (together the table forms a map/board). Players (2-4) each have their own pawns that float over the board using z-index (they are GIF-images).
I actually did this program last fall and it works fine and dandy except Firefox and Google Chrome have a bit odd behaviour when it comes to placing GIF images (players' pawns) on the board on startup. They get into proper position after some refreshing and moving pawns works properly always. Just at the startup (unless page has been refreshed) will the pawn start at upper middle and not in their starting positions. This works perfectly fine in IE 7, IE 8 and Opera by the way.
Here is the code where I set the starting position of players' pawns upon starting. - var h = 0;
-
while(h<pelaajia){ //pelaajia = amout of players
-
var x = findPosX(document.getElementById(vuorotaulu[h].id)); //array containing player objects
-
var y = findPosY(document.getElementById(vuorotaulu[h].id));
-
document.getElementById(vuorotaulu[h].nappula).style.left = x + 20 + "px"; //nappula is for pawn, it is one the variables for player object
-
document.getElementById(vuorotaulu[h].nappula).style.top = y + (h * 5) + "px";
-
h++;
-
}
And findPosX and findPosY: - function findPosX(obj){
-
var curleft = 0;
-
if(obj.offsetParent){
-
while(1){
-
curleft += obj.offsetLeft;
-
if(!obj.offsetParent)break;
-
obj = obj.offsetParent;
-
}
-
}else if(obj.x)curleft += obj.x;
-
return curleft;
-
}
-
-
function findPosY(obj){
-
var curtop = 0;
-
if(obj.offsetParent){
-
while(1){
-
curtop += obj.offsetTop;
-
if(!obj.offsetParent)break;
-
obj = obj.offsetParent;
-
}
-
}else if(obj.y)curtop += obj.y;
-
return curtop;
-
}
Any insight or help on the matter is appreciated.
10 2793 gits 5,390
Expert Mod 4TB
when is the code executed? in the page's onload handler?
kind regards
Actually no. There is a html page which has a form for player names and description of game with rules. All that is inside div element which's contents will be replaced by gametable (and other game related stuff) via Javascript function tarkista() that is called from form.
This is function that is called from form of html page (validates and builds gametable also creates new Peli object (Game object)): - function tarkista(){
-
var i = 0;
-
var pelaajaa, pelaajab, pelaajac, pelaajad;
-
pelaajaa = document.getElementById('nimia').value;
-
pelaajab = document.getElementById('nimib').value;
-
pelaajac = document.getElementById('nimic').value;
-
pelaajad = document.getElementById('nimid').value;
-
if(pelaajaa !== ""){vuorotaulu[i] = new Pelaaja(pelaajaa, 500, "8_5", i, 47); i++;}
-
if(pelaajab !== ""){vuorotaulu[i] = new Pelaaja(pelaajab, 500, "8_6", i, 48); i++;}
-
if(pelaajac !== ""){vuorotaulu[i] = new Pelaaja(pelaajac, 500, "8_7", i, 49); i++;}
-
if(pelaajad !== ""){vuorotaulu[i] = new Pelaaja(pelaajad, 500, "8_8", i, 50); i++;}
-
if(i < 2){
-
document.getElementById('tarkka').innerHTML = "Moninpelissä täytyy olla vähintään kaksi pelaajaa"; //Peli ei käynnisty ellei tämä ehto täyty
-
}else{
-
//laitetaan nappulat sivulle
-
var sivunteko = "";
-
if(pelaajaa !== ""){
-
sivunteko = sivunteko +"<div class='position_player1' id='position_player1'><img src='pelaajat/player1.gif' id='player1'></div>";
-
}
-
if(pelaajab !== ""){
-
sivunteko = sivunteko +"<div class='position_player2' id='position_player2'><img src='pelaajat/player2.gif' id='player2'></div>";
-
}
-
if(pelaajac !== ""){
-
sivunteko = sivunteko +"<div class='position_player3' id='position_player3'><img src='pelaajat/player3.gif' id='player3'></div>";
-
}
-
if(pelaajad !== ""){
-
sivunteko = sivunteko +"<div class='position_player4' id='position_player4'><img src='pelaajat/player4.gif' id='player4'></div>";
-
}
-
sivunteko = sivunteko + "<table class='pelaajat'><tr>";
-
if(pelaajaa !== ""){
-
sivunteko = sivunteko +"<td class='pelaaja1'>"+pelaajaa+"<div id='"+pelaajaa+"'>Rahaa: 500</div></td>";
-
}
-
if(pelaajab !== ""){
-
sivunteko = sivunteko +"<td class='pelaaja2'>"+pelaajab+"<div id='"+pelaajab+"'>Rahaa: 500</div></td>";
-
}
-
if(pelaajac !== ""){
-
sivunteko = sivunteko +"<td class='pelaaja3'>"+pelaajac+"<div id='"+pelaajac+"'>Rahaa: 500</div></td>";
-
}
-
if(pelaajad !== ""){
-
sivunteko = sivunteko +"<td class='pelaaja4'>"+pelaajad+"<div id='"+pelaajad+"'>Rahaa: 500</div></td>";
-
}
-
//noppa
-
sivunteko = sivunteko +"<td><div class='nop'><img src='noppa/noppa_6.png' id='noppa'></div></td>";
-
sivunteko = sivunteko +"</tr></table>";
-
//kartta
-
sivunteko = sivunteko +"<table id='kartta' class='kartta'>";
-
sivunteko = sivunteko +"<tr>";
-
sivunteko = sivunteko +"<td colspan='12'><img src='palikat/yla.png'></td>";
-
sivunteko = sivunteko +"</tr>";
-
sivunteko = sivunteko +"<tr>";
-
sivunteko = sivunteko +"<td rowspan='8'><img src='palikat/vasen.png'></td>";
-
sivunteko = sivunteko +"<td><img src='palikat/1_1.png' id='0' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko +"<td><img src='palikat/1_2.png' id='1' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/1_3.png' id='2' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/1_4.png' id='3' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/1_5.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/1_6.png' id='4' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/1_7.png' id='5' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/1_8.png' id='6' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/1_9.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/1_10.png'></td>";
-
sivunteko = sivunteko + "<td rowspan='8'><img src='palikat/oikea.png'></td>";
-
sivunteko = sivunteko + "</tr>";
-
sivunteko = sivunteko + "<tr>";
-
sivunteko = sivunteko + "<td><img src='palikat/2_1.png' id='7' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/2_2.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/2_3.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/2_4.png' id='8' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/2_5.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/2_6.png' id='9' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/2_7.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/2_8.png' id='10' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/2_9.png' id='11' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/2_10.png' id='12' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "</tr>";
-
sivunteko = sivunteko + "<tr>";
-
sivunteko = sivunteko + "<td><img src='palikat/3_1.png' id='13' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/3_2.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/3_3.png' id='14' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/3_4.png' id='15' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/3_5.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/3_6.png' id='16' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/3_7.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/3_8.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/3_9.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/3_10.png' id='17' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "</tr>";
-
sivunteko = sivunteko + "<tr>";
-
sivunteko = sivunteko + "<td><img src='palikat/4_1.png' id='18' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/4_2.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/4_3.png' id='19' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/4_4.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/4_5.png' id='20' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/4_6.png' id='21' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/4_7.png' id='22' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/4_8.png' id='23' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/4_9.png' id='24' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/4_10.png' id='25' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "</tr>";
-
sivunteko = sivunteko + "<tr>";
-
sivunteko = sivunteko + "<td><img src='palikat/5_1.png' id='26' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/5_2.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/5_3.png' id='27' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/5_4.png' id='28' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/5_5.png' id='29' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/5_6.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/5_7.png' id='30' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/5_8.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/5_9.png' id='31' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/5_10.png'></td>";
-
sivunteko = sivunteko + "</tr>";
-
sivunteko = sivunteko + "<tr>";
-
sivunteko = sivunteko + "<td><img src='palikat/6_1.png' id='32' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/6_2.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/6_3.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/6_4.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/6_5.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/6_6.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/6_7.png' id='33' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/6_8.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/6_9.png' id='34' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/6_10.png'></td>";
-
sivunteko = sivunteko + "</tr>";
-
sivunteko = sivunteko + "<tr>";
-
sivunteko = sivunteko + "<td><img src='palikat/7_1.png' id='35' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/7_2.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/7_3.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/7_4.png' id='36' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/7_5.png' id='37' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/7_6.png' id='38' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/7_7.png' id='39' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/7_8.png' id='40' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/7_9.png' id='41' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/7_10.png' id='42' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "</tr>";
-
sivunteko = sivunteko + "<tr>";
-
sivunteko = sivunteko + "<td><img src='palikat/8_1.png' id='43' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/8_2.png' id='44' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/8_3.png' id='45' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/8_4.png' id='46' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/8_5.png' id='47' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/8_6.png' id='48' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/8_7.png' id='49' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/8_8.png' id='50' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/8_9.png'></td>";
-
sivunteko = sivunteko + "<td><img src='palikat/8_10.png' id='51' onClick='peli.klikkaus(this.id)'></td>";
-
sivunteko = sivunteko + "</tr>";
-
sivunteko = sivunteko + "<tr>";
-
sivunteko = sivunteko + "<td colspan='12'><img src='palikat/ala.png'>";
-
sivunteko = sivunteko + "</tr>";
-
sivunteko = sivunteko + "</table>";
-
sivunteko = sivunteko + "<div id='vuoro' align='center' class='vuoro'>Vuorotaulu.</div>";
-
document.getElementById('sivu').innerHTML = sivunteko;
-
peli = new Peli(i); //tehdään peliolio
-
}
-
}
Here is the code for Peli() which puts the pawns into starting position among other things: - function Peli(pelaajia){
-
this.klikkaus = klikattu; // klikattu funktio pelille
-
this.pelaajia = pelaajia; //pelaajien määrä
-
this.vuoroja = vuoro; // vuoro funktio pelille
-
this.vaihda = vaihdavuoro; // vaihdavuoro funktio pelille
-
var noppaluku = 0; // apumuuttuja nopan silmäluvun muistamista varten
-
var osta = false;
-
var odota, odota2, odota3 = false;
-
var mikaostetaan = 999;
-
// arvotaan paikoille laput:
-
var k = 0, aarre = 0, varas = 0;
-
while(k<52){
-
if(paikat[k].onlappu){
-
var onkotehtylappu = false;
-
while(!onkotehtylappu){
-
var randomi = Math.ceil(Math.random() * 4);
-
if(randomi == 1 && aarre !== 1 && !(Math.ceil(Math.random() * 3) == 1)){
-
paikat[k].lappu = 1;
-
aarre = 1;
-
onkotehtylappu = true;
-
}
-
if(randomi == 2 && varas < (pelaajia - 1) && !(k == 51 && aarre === 0)){
-
paikat[k].lappu = 2;
-
varas++;
-
onkotehtylappu = true;
-
}
-
if(randomi == 3 && !(k == 51 && aarre === 0)){
-
paikat[k].lappu = 3; //jalokivi
-
onkotehtylappu = true;
-
}
-
if(randomi == 4 && !(k == 51 && aarre === 0)){
-
if(Math.ceil(Math.random() * 2) == 1) paikat[k].lappu = 4; //tyhjä lappu
-
else paikat[k].lappu = 5; //uusi vuoro lappu
-
onkotehtylappu = true;
-
}
-
}
-
}
-
k++;
-
}
-
//korjataan pelaajien sijainti kartalla:
-
var h = 0;
-
while(h<pelaajia){
-
var x = findPosX(document.getElementById(vuorotaulu[h].id));
-
var y = findPosY(document.getElementById(vuorotaulu[h].id));
-
document.getElementById(vuorotaulu[h].nappula).style.left = x + 20 + "px";
-
document.getElementById(vuorotaulu[h].nappula).style.top = y + (h * 5) + "px";
-
h++;
-
}
-
//aloitetaan peli:
-
this.vuoroja();
-
}
gits 5,390
Expert Mod 4TB
have a look at the firefox-error console or use firbebug for firefox to see whether the node could be retrieved reliably with your current code ... otherwise call the code from the onload-handler of the page this should solve the problem ...
kind regards
@gits
Error console gave me nothing. But I made separate function that sets pawns to starting positions. Function is called upon loading last image of the generated table (called via onload-handler). Works like a charm now. Thanks for the help.
gits 5,390
Expert Mod 4TB
glad to hear that you got it working :) ...
kind regards
gits 5,390
Expert Mod 4TB
ok ;) ... i guess it's Finnish? and the graphics could be much worser ... so i find it quite good ... :)
kind regards,
gits
@gits
That's right. Are you familiar with Finnish language? Or did you just google translate it? ;)
Thanks for the help again, BYTES is the best forum when it comes to IT. At least from those few forums I viewed/know ;?).
gits 5,390
Expert Mod 4TB
nej .... jag talar lite svenska :) ... and it just looked Finnish so i said 'i guess' :)
I've been watching the TV show "Lost" lately...it reminds me of it (the plane in the corner approaching what looks like an island )
Not a bad looking game :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: rsteph |
last post by:
I've got a site that appears properly in both IE and Netscape for has all sorts of appearance issues in Mozilla Firefox. I've looked around for some points on the web that help explain the issue, but...
|
by: tim |
last post by:
I am using foldoutmenu 3 and am having problems with viewing my menus
in firefox. On my sub3 menus i have more than one line of text in some
places. firefox does not recognise that there is more...
|
by: agbee1 |
last post by:
Hello:
I've finally made the effort to ween myself from overly using tables and use CSS for my positioning. However, I am having a problem with my navigational menu properly aligning in Firefox,...
|
by: firstexact |
last post by:
Hi guys,
First post, hope you can help, I have done two sites www.trisant.co.uk and my own www.firstexact.co.uk. The 2 x 2 grid I originally envisaged goes haywire in Firefox as I get a 4 high by...
|
by: rosaryshop |
last post by:
I'm working a jewelry/rosary design web site at http://www.rosaryshop.com/rosariesAndKits2.php.
As the user makes selections, it updates images of various parts, giving them a preview of the...
|
by: littlealex |
last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS!
In IE6 the text for the following page doesn't display properly - rather than being...
|
by: Steve |
last post by:
Hi All
I have an asp.net 2.0 website with the following css file
It uses Master pages and in Firefox 3.04 for windows only, 3 of the web
pages don't display the Master page properly
The...
|
by: mike57 |
last post by:
The minimal AJAX script below works in Firefox, but not in IE, Opera, or Chrome. I could use some suggestions or referrals to resources that will help me get the script working in other browsers.
...
|
by: oranoos3000 |
last post by:
hi
would you please help me
i have a online shopping center that i show pictures of the my product in home page.
in the InterExplorer pictures is shown correctly but in Firefox browser is shown...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |