A
A
Artem Shchurin2015-10-30 17:38:19
JavaScript
Artem Shchurin, 2015-10-30 17:38:19

How to wait for the newly inserted xml document to be rendered in the DOM?

1. I load svg
2. I paste it into the house
3. I give it to PanZoom
4. I process active elements
, the fact is that SVG is displayed only after the 4th point,
and I would show it to the user as soon as it has loaded and inserted, because point 3 and 4 can go about 10-20 seconds
wrapped the code with 3 and 4 points in setTimeout in order to queue, which did not help
as much as possible with JS execution, tell the browser to start rendering

var container = $('#container');

// 1: Загружаю svg
var ajax = $.ajax({url, succsess: succsess});

function succsess(xml){


    // 2: Вставиляю в дерево документа и обрабатываю

  var normalizeXML = Helper.getNormalizeXML(xml), svg;

  container.append(normalizeXML);

  svg = container.find('svg');

  svg.attr('width', container.outerWidth()).attr('height', container.outerHeight());

    // 3: Отдаю svg для скрикту зума
    // этот скрипт очень долго орабатывает
    // зависит от размера svg, бывает и 10-20 сек.
    // в ie на этот момент svg еще не отобразилась 

  Helper.svgPanZoom(svg);

    // 4: обработка активных элементов на svg

  parseSvg(svg);

    // для ie отображение на экране произойдёт тут
    // но если сделать так

    /*	setTimeout(function(){

        Helper.svgPanZoom(svg);

        parseSvg(svg);


      }, 5000);*/

    // svg отобразится раньше чем отработает скрипт зума и парсинг активных элементов
    // проблема не касается нормальных браузеров
    // к сожалению наши клиенты пользуют ie 10

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twobomb, 2015-10-31
@twobomb

continer.append(normalizeXML);// then container should have a variable, but you have continer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question