Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Something like this should work. This lets the elements animate themselves based on state. On click, if the element is being activated, loop through and deactivate the others.</p> <pre><code>// An animator function which will animate based on node state var animate = function(st) { var fill = st.node.state ? "#fff" : "#555"; st.animate({fill: fill, stroke: "#fff"}, 100); } for (i in aus) { (function (st) { st.node.state = 0; st.node.onmouseover = function () { if (!this.state) st.animate({fill: "#8fbf27", stroke: "#fff"}, 100); }; st.node.onmouseout = function () { animate(st); }; st.node.onclick = function () { this.state = 1 - this.state; animate(st); // if the node is deactivated stop now if (!this.state) return; // otherwise deactivate and animate the other nodes for (i in aus) { // if node is `this` or node is already deactivated, continue if (aus[i].node === this || !aus[i].node.state) continue; // otherwise deactivate and animate aus[i].node.state = 0; animate(aus[i]); } }; }(aus[i])); } </code></pre> <p>Alternatively, if only one is activated at a time, you might just store a reference to the one activated node and avoid looping.</p> <pre><code>// A reference to the active element var activeEl; // animate based on whether the st is the active element var animate = function(st) { var fill = activeEl === st ? "#fff" : "#555"; st.animate({fill: fill, stroke: "#fff"}, 100); } for (i in aus) { (function (st) { st.node.onmouseover = function () { if (!this.state) st.animate({fill: "#8fbf27", stroke: "#fff"}, 100); }; st.node.onmouseout = function () { animate(st); }; st.node.onclick = function () { if (!activeEl || activeEl !== st) { var el = activeEl; activeEl = st; if (el) animate(el); } else { activeEl = null; } animate(st); }; }(aus[i])); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload