Note that there are some explanatory texts on larger screens.

plurals
  1. PO$(window).load firing before embedded svg is done loading in chrome
    primarykey
    data
    text
    <p>I am loading an svg object to manipulate. It appears that when i click on the link to enter the page, the svg loads and the $(window).load fires just before the svg is loaded. However, it works normally when you refresh the page. I think perhaps it is because it's loading the svg from cache on the first go? Is there anything i can do? The only things i can think of are very shoddy, like adding a short delay... and this doesn't seem to be a problem in firefox. only chrome.</p> <pre><code>function getSubDocument(embedding_element) { if(embedding_element.contentDocument) { return embedding_element.contentDocument; } else { var subdoc = null; try { subdoc = embedding_element.getSVGDocument(); } catch(e) {} return subdoc; } } $(window).load(function () { alert('loading complete'); var a = document.getElementById("hero"); var svgDoc = getSubDocument(a); //a.contentDocument; //get the inner DOM of alpha.svg var hair = svgDoc.getElementById("hair"); var shirt = svgDoc.getElementById("body"); var head = svgDoc.getElementById("head"); var left_arm = svgDoc.getElementById("left_arm"); var right_arm = svgDoc.getElementById("right_arm"); var pants = svgDoc.getElementById("pants"); //var weapon = svgDoc.getElementById('axe'); //weapon.setAttribute('display', ""); hair.setAttribute("fill", '{{ profile.hair_color }}'); shirt.setAttribute("fill", '{{ profile.shirt_color }}'); head.setAttribute("fill", '{{ profile.skin_color }}'); left_arm.setAttribute("fill", '{{ profile.skin_color }}'); right_arm.setAttribute("fill", '{{ profile.skin_color }}'); pants.setAttribute("fill", '{{ profile.pants_color }}'); $("input[name='colorType']").change(function () { var ct = $("input[name='colorType']:checked").val(); var c; if(ct == 'Hair') { c = $("#id_hair_color").val(); } else if(ct == 'Shirt') { c = $("#id_shirt_color").val(); } else if(ct == 'Skin') { c = $("#id_skin_color").val(); } else if(ct == 'Pants') { c = $("#id_pants_color").val(); } $.farbtastic('#colorpicker').setColor(c); }); $('#colorpicker').farbtastic(function (e) { var ct = $("input[name='colorType']:checked").val(); c = $.farbtastic('#colorpicker').color; if(ct == 'Hair') { hair.setAttribute('fill', c); $("#id_hair_color").val(c); } else if(ct == 'Shirt') { shirt.setAttribute('fill', c); $("#id_shirt_color").val(c); } else if(ct == 'Skin') { head.setAttribute('fill', c); left_arm.setAttribute('fill', c); right_arm.setAttribute('fill', c); $("#id_skin_color").val(c); } else if(ct == 'Pants') { pants.setAttribute('fill', c); $("#id_pants_color").val(c); } // conole.log(JSON.stringify($.farbtastic('#colorpicker').color)); // hair.setAttribute("fill", c); }); $.farbtastic('#colorpicker').setColor("#f0ff5f"); // var sword = svgDoc.getElementById("right_arm"); //get the inner element by id // // sword.addEventListener("mousedown",function(){alert('hello world!')},false); // alert('got to here'); }); </code></pre> <p>html</p> <pre><code>&lt;embed src="/static/images/hero2.svg" style="width: 100%" id="hero" type="image/svg+xml" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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