Insert object (jquery) delay?

前端 未结 6 435
天命终不由人
天命终不由人 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:37

    You cannot access the images width and height until after the images loads. Thats why the setTimeout works for you sometimes. Use the image.load() call back function to trigger the code you require to be run after the image has loaded.

        var imgInner = jQuery('', {           
           src: img
        }).load(function () {
           jQuery(this).appendTo('#' + objId)
           restoreSize(myNewImg, this);           
           //and so on
        });
    

提交回复
热议问题