QA@IT
«回答へ戻る

回答を投稿

こんにちは。こうですかね。

function move(){
    var get, rand, x, timer;
    get = document.getElementById("pic");
    x = Math.floor(Math.random() * 10);
    rand = Math.random();
    if(rand < 0.25){
        get.style.top = get.offsetTop + x + "px";
    }else if(rand < 0.50){
        get.style.top = get.offsetTop - x + "px";
    }else if(rand < 0.75){
        get.style.left = get.offsetLeft + x + "px";
    }else{
        get.style.left = get.offsetLeft - x + "px";
    }
    timer = setTimeout("move()", 100);
}
こんにちは。こうですかね。

```javascript
function move(){
    var get, rand, x, timer;
    get = document.getElementById("pic");
    x = Math.floor(Math.random() * 10);
    rand = Math.random();
    if(rand < 0.25){
        get.style.top = get.offsetTop + x + "px";
    }else if(rand < 0.50){
        get.style.top = get.offsetTop - x + "px";
    }else if(rand < 0.75){
        get.style.left = get.offsetLeft + x + "px";
    }else{
        get.style.left = get.offsetLeft - x + "px";
    }
    timer = setTimeout("move()", 100);
}
```