私の状況では、javascript を使用して画像のサイズを確認し、その幅に応じてコードを実行する必要があります。私のコードは次のとおりです。
var width, height;
var img = new Image();
img.src = "pool.jpg";
img.onload = function () {
width = this.width;
height = this.height;
console.log(width);
}
console.log(width);
if (width > 0) {
console.log('in condition check');
//Some code to be executed
}
//Some other code to be executed which cannot be put in the onload portion
問題はimg.onload
、以下のコードの実行が終了した後にのみその部分が機能することimg.onload
です.関数をトリガーしてコード実行の同期的な方法で行く方法はありますか.