garyblackpool Posted November 3, 2009 Share Posted November 3, 2009 hi,U have been trying to change the background position property but mozilla brower does not support style.backgroundPositionX but mozilla does not except that. So I have now changed my function to this but it does now work. Could someone help thanks.gary var x = 10; //Starting Location - leftvar y = 10; //Starting Location - topvar dest_x = 400; //Ending Location - leftvar dest_y = 200; //Ending Location - topintervalX = Math.ceil(dest_x/dest_y);intervalY = Math.ceil(dest_y/dest_x)function moveimg() {if(x > dest_x) {x -= intervalX;} else if(x < dest_x) {x += intervalX}if(y > dest_y) {y -= intervalY;} else if(y < dest_y) {y += intervalY}// Just in case we're closer to the destination than the motion intervalif(Math.abs(dest_x - x) < intervalX) x = dest_x;if(Math.abs(dest_y - y) < intervalY) y = dest_y;if (x != dest_x || y != dest_y) {// Repeat the operationdocument.getElementById("landscape").style.backgroundPosition = 'x+'px' 'y+'px";window.setTimeout(moveimg,300);}}</script> Link to comment Share on other sites More sharing options...
thescientist Posted November 3, 2009 Share Posted November 3, 2009 document.getElementById("landscape").style.backgroundPosition = 'x+'px' 'y+'px"; is it these mismatching quotation marks?plus, would you need to have a comma inbetween the x and y coordinates? Or maybe parantheses around them? Link to comment Share on other sites More sharing options...
garyblackpool Posted November 3, 2009 Author Share Posted November 3, 2009 I thought i had it working but i dont (thats why this is edited). I way i got it to working firefox was: document.getElementById("landscape").style.backgroundPosition = x+'px';document.getElementById("landscape").style.backgroundPosition = y+'px'; But that just adds the x and y destination together.Cheers Link to comment Share on other sites More sharing options...
garyblackpool Posted November 3, 2009 Author Share Posted November 3, 2009 hi,I now have the function working usingdocument.getElementById("landscape").style.backgroundPosition = x+'%' +y+'%';but i have a new problem which is the function itself., if i move an image it will work fine but with the background it does not. If Y is set 100, and X set 200, when it gets to Y it just stops. I think the problem is with thisif (x != dest_x || y != dest_y) which i have changed to && and !=. Is it that or a problem with using background percentages?Thanks Link to comment Share on other sites More sharing options...
Ingolme Posted November 3, 2009 Share Posted November 3, 2009 hi,I now have the function working usingdocument.getElementById("landscape").style.backgroundPosition = x+'%' +y+'%';but i have a new problem which is the function itself., if i move an image it will work fine but with the background it does not. If Y is set 100, and X set 200, when it gets to Y it just stops. I think the problem is with thisif (x != dest_x || y != dest_y) which i have changed to && and !=. Is it that or a problem with using background percentages?ThanksYou need to put a space between the first value and the second. And if you use percentages rather than pixels, it's not going to get where you want it to.document.getElementById("landscape").style.backgroundPosition = x+'px ' +y+'px'; Link to comment Share on other sites More sharing options...
garyblackpool Posted November 3, 2009 Author Share Posted November 3, 2009 You need to put a space between the first value and the second. And if you use percentages rather than pixels, it's not going to get where you want it to.document.getElementById("landscape").style.backgroundPosition = x+'px ' +y+'px'; Oh whoop that works. I thought tried that. Thanks.Do you know what it would be just to effect the Y-axis,Thanks you very muchGary Link to comment Share on other sites More sharing options...
Ingolme Posted November 3, 2009 Share Posted November 3, 2009 Oh whoop that works. I thought tried that. Thanks.Do you know what it would be just to effect the Y-axis,Thanks you very muchGaryYou have to leave the X value constant, like this:document.getElementById("landscape").style.backgroundPosition = '5px ' +y+'px';But you really should keep track of both X and Y values before applying the backgroundPosition property. Maybe you want an extra variable constX that contains an unchanged value of X. Link to comment Share on other sites More sharing options...
garyblackpool Posted November 3, 2009 Author Share Posted November 3, 2009 You have to leave the X value constant, like this:document.getElementById("landscape").style.backgroundPosition = '5px ' +y+'px';But you really should keep track of both X and Y values before applying the backgroundPosition property. Maybe you want an extra variable constX that contains an unchanged value of X.Oh cheers thanksgary Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.