drawImage doesn't work when I refer to an image in another javascript file

前端 未结 1 490
隐瞒了意图╮
隐瞒了意图╮ 2021-01-23 23:46

(I\'ll show the pure javascript below) I\'ve got these two lines of code that are, in my mind, doing the exact same thing but one of them reports an error. This appears in a fi

相关标签:
1条回答
  • 2021-01-24 00:42

    You can try to solve this two ways -

    Method 1

    Move the scripts to the bottom of the file before the closing tag </body>. This way all DOM elements are loaded before any JavaScript is executed.

    Method 2

    Try to wrap all inits that are dependent on DOM elements in the window's load event inside the script files themselves in case you cannot or don't want to move them to the bottom:

    window.addEventListener('load', function() {
    
        /// init the resource here...
    
    }, false);
    
    0 讨论(0)
提交回复
热议问题