Insert object (jquery) delay?

前端 未结 6 430
天命终不由人
天命终不由人 2021-01-12 21:49

I allow the user to insert an object, an image, and then i call a function on that object. What seems randomly to me, sometimes it works and sometimes not, I guess it has t

6条回答
  •  别那么骄傲
    2021-01-12 22:51

    could this work for you?

          function add_image(img) {
            var objCount = count_objects() + 1;
            var objId = 'object_' + objCount;
    
            var myNewImg = jQuery('
    ', { id: objId, class: 'object_image invisible' }).appendTo('#objectbox'); $('#' + objId).attr('namn', objId) $('#' + objId).addClass('lockedAspectRatio') var imgInner = jQuery('', { id: objId, 'class': 'object_image_inner', src: img }).load(function () { imgInner.appendTo('#' + objId) restoreSize(myNewImg, imgInner); $(myNewImg).removeClass('invisible'); }); window.objectCounter++; prepare_editmode(); //reset the flag and the temporary image field now that image adding is complete $('#imageGhost').val(null); }

    and BTW you've duplicate ids for myNewImg and imgInner

提交回复
热议问题