-2

I have two javascripts I want to run at the same time, to create a layered animation. Both, are essentially the same script, but with different settings

I use <body onload="animate(); ch();"> to load each function.

separately, both loops work fine. when i try to run both at the same time, whichever is first in the document runs fine, but the second will not run.

I am new to jsfiddle, but jsfiddle balks about use of document.write and I have no idea how to include more than one javascript into jsfiddle.

both scripts are loops, and should loop indefinitely. separately, here is what each should look like: http://nanocluster.umeche.maine.edu/scope/

UPDATE: HTML Source:

http://nanocluster.umeche.maine.edu/scope/saw.html

Can someone point out how I can have both scripts looping at the same time?

    <!DOCTYPE html><html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="shortcut icon" href="http://www.hackmaine.org/favicon.ico">
<link rel="stylesheet" type="text/css" href="main.css">
<title>Epic Lulz</title>
<style> p.ex {color:rgb(0,0,0);}</style>
</head>
<body onload="animate(); ch();">
    <script type="text/javascript" src="animate.js"></script>
    <script type="text/javascript" src="ch.js"></script>
<div id="background">
<pre>
+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
|         |         |         |         |         |         |         |         |         |         |
|         |         |         |         |         |         |         |         |         |         |
|         |         |         |         |         |         |         |         |         |         |
|         |         |         |         |         |         |         |         |         |         |
+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
|         |         |         |         |         |         |         |         |         |         |
|         |         |         |         |         |         |         |         |         |         |
|         |         |         |         |         |         |         |         |         |         |
|         |         |         |         |         |         |         |         |         |         |
+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
|         |         |         |         |         |         |         |         |         |         |
|         |         |         |         |         |         |         |         |         |         |
|         |         |         |         |         |         |         |         |         |         |
|         |         |         |         |         |         |         |         |         |         |
+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
|         |         |         |         |         |         |         |         |         |         |
|         |         |         |         |         |         |         |         |         |         |
|         |         |         |         |         |         |         |         |         |         |
|         |         |         |         |         |         |         |         |         |         |
+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
_____________________________________________________________________________________________________
t1:288 ms  t2:480 ms    Display Mode: Normal: Peak Detect    Vectors: OFF       Grid = FULL
</pre>
</div>
<div class="container" style=" visibility: hidden; color: rgb(254, 0, 0);" id="cat1">
<pre>

  ┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐   
  │        │    │        │    │        │    │        │    │        │    │        │    │        │
──┘        └────┘        └────┘        └────┘        └────┘        └────┘        └────┘


</pre></div>
<div class="container" style=" visibility: hidden; color: rgb(254, 0, 0);" id="cat2">
<pre>

┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐   
│        │    │        │    │        │    │        │    │        │    │        │    │        │
         └────┘        └────┘        └────┘        └────┘        └────┘        └────┘        └── 


</pre></div>
<div class="container" style="visibility: hidden; color: rgb(254, 0, 0);" id="cat3">
<pre>

  ┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐   
  │        │    │        │    │        │    │        │    │        │    │        │    │        │
──┘        └────┘        └────┘        └────┘        └────┘        └────┘        └────┘


</pre></div>
<div class="container" style="visibility: hidden; color: rgb(254, 0, 0);" id="cat4">
<pre>

┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐   
│        │    │        │    │        │    │        │    │        │    │        │    │        │
         └────┘        └────┘        └────┘        └────┘        └────┘        └────┘        └── 


</pre></div>
<div class="container" style=" visibility: hidden; color: rgb(254, 0, 0);" id="cat5">
<pre>

  ┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐    ┌────────┐   
  │        │    │        │    │        │    │        │    │        │    │        │    │        │
──┘        └────┘        └────┘        └────┘        └────┘        └────┘        └────┘


</pre></div>



    <div class="test" style="visibility: hidden; color: rgb(0, 0, 254);" id="cat1">
    <pre>





&Lambda;   &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;                                              
 \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /                                                   
  V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    

</pre></div>


    <div class="test" style="visibility: hidden; color: rgb(0, 0, 254);" id="cat2">
    <pre>





  &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;                                              
 / \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \                                                    
V   V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    \   

</pre></div>

    <div class="test" style="visibility: hidden; color: rgb(0, 0, 254);" id="cat3">
<pre>





   &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;                                              
\ / \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \                                                    
 V   V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V       

</pre></div>

    <div class="test" style="visibility: hidden; color: rgb(0, 0, 254);" id="cat4">
    <pre>





&Lambda;   &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;                                              
 \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /                                                   
  V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    

</pre></div>

    <div class="test" style="visibility: hidden; color: rgb(0, 0, 254);" id="cat5">
    <pre>





  &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;    &Lambda;                                              
 / \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \ /  \                                                    
V   V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    V    \   

</pre></div>

</body></html>
j0h
  • 1,675
  • 6
  • 27
  • 50
  • Can you demonstrate how you "run both at the same time" versus what you've provided in the question? – Jared Farrish Jul 24 '14 at 22:14
  • 1
    Looping one after the other quickly enough gives the impression of at the same time, but you could try with setTimeOut to make asynchronic calls – juvian Jul 24 '14 at 22:18
  • If i could run both at the same time I wouldn't have this question. I will post the code though. – j0h Jul 24 '14 at 22:23

1 Answers1

0

I assume that you're running these in a browser given your statement in the 3rd paragraph: "...whichever is first in the document...".

If that assumption is correct, there is no way to cause these to run in-parallel in your browser.

ussabin
  • 51
  • 1
  • 4
  • I think I can do it with webworkers. Though I just started reading about them, I do have multple sample scripts running concurrently.http://www.html5rocks.com/en/tutorials/workers/basics/ – j0h Jul 26 '14 at 02:54
  • It doesn't appear that WebWorkers allow you to operate on the DOM. You can run background processes that perform calculations and other useful things; but, I don't think the DOM can be operated on by concurrent threads. – ussabin Jul 28 '14 at 18:58