AzureZhen AzureZhen - 4 months ago 13
HTML Question

Changing part of a image url every x amount of seconds

Alright so my question today is bit of a weird one. Basically what I'm trying to do is take this image code

<img src="3d.php?a=-25&w=35&wt=-45&abg=0&abd=-30&ajg=-25&ajd=30&ratio=13&format=png&displayHairs=true&headOnly=false&login=">

and have it update only the w=35 part of it and have it add +1 to that number, either forever or until it hits 360 then resets it to 0, every x amount of seconds.

The point of this is to create what looks like a spinning image, instead of spawning each possible wt= from 0 to 360 by hand.


Try this:

<img id="threedee">

In your script, further down the page:

var w = 35;
var x = 5; // every 5 seconds
var threedee = document.getElementById("threedee");
setInterval(function () {
    w = (w + 1) % 360;
    var src = "3d.php?a=-25&w=" + w + "&wt=-45&abg=0&abd=-30&ajg=-25&";
    src += "ajd=30&ratio=13&format=png&displayHairs=true&headOnly=false&login=";
    threedee.src = src;
}, x * 1000);