previous | top | next

Spawing 'threads' from event handlers

      function animation() {
        var elem = document.createElement("div");
        elem.setAttribute("style",
          "position:relative; width:20px; height:20px;background-color:red;");
        document.getElementById("playpen").appendChild(elem);

        for (var x=0; x<400; x+= 5) {
          elem.style.left = x;
          hold(10);
        }
        elem.parentNode.removeChild(elem);
      }
In <body>:
      <button onclick="animation();">Spawn animation</button>

High-level concurrency for JS - http://www.croczilla.com/stratified