D
D
dm2015-05-02 15:34:33
JavaScript
dm, 2015-05-02 15:34:33

Why does this code not resize the image?

The JavaScript book has this example:

<head>
  <script>
      function resizeRock() {
        document.getElementById('rockimg').style.height =
        (document.body.clientHeight - 100) * 0.9;
      }
    </script>
</head>
<body onload="resizeRock()">
    <img id="rockimg" src="pegoet.png">
</body>

The image should be full height (~90%) when the page loads. But it doesn’t work for me, although I copied everything 1 to 1. What is the reason, what is wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
gracer, 2015-05-02
@Chekhoved

Forgotten units of measurement

function resizeRock() {
    document.getElementById('rockimg').style.height =
        ((document.body.clientHeight - 100) * 0.9)+"px";
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question