Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Cách phát file đa phương tiện (multimedia) bằng JavaScript

Ví dụ đơn giản về animation (di chuyển ảnh) - thường dùng cho multimedia interaction:

Ví dụ: Di chuyển ảnh

<html>
  <head>
    <title>JavaScript Animation</title>
    <script>
      var imgObj = null;
      function init() {
        imgObj = document.getElementById('myImage');
        imgObj.style.position = 'relative';
        imgObj.style.left = '0px';
      }
      function moveRight() {
        imgObj.style.left = parseInt(imgObj.style.left) + 10 + 'px';
      }
      window.onload = init;
    </script>
  </head>
  <body>
    <form>
      <img id="myImage" src="/images/html.gif" />
      <p>Click nút để di chuyển ảnh sang phải</p>
      <input type="button" value="Click Me" onclick="moveRight();" />
    </form>
  </body>
</html>