writes a function that is referenced on the page and called when the picture is loaded. The function works, but an error is displayed on the console.
when you take that function out to make a demo, you don"t report an error, but when you put it with other js code, you keep reporting an error. I don"t know why. I hope the gods who understand will give us some advice.
Uncaught ReferenceError: AutoResizeImage is not defined
code is as follows:
js
/ / Picture proportional scaling
function AutoResizeImage(maxWidth, maxHeight, objImg) {
var img = new Image();
img.src = objImg.src;
var hRatio;
var wRatio;
var Ratio = 1;
var w = img.width;
var h = img.height;
wRatio = maxWidth / w;
hRatio = maxHeight / h;
if (maxWidth == 0 && maxHeight == 0) {
Ratio = 1;
} else if (maxWidth == 0) {//
if (hRatio < 1) Ratio = hRatio;
} else if (maxHeight == 0) {
if (wRatio < 1) Ratio = wRatio;
} else if (wRatio < 1 || hRatio < 1) {
Ratio = (wRatio <= hRatio ? wRatio : hRatio);
}
if (Ratio < 1) {
w = w * Ratio;
h = h * Ratio;
}
objImg.height = h;
objImg.width = w;
}
html
<center><img onerror="this.src="/Content/images/nopic.jpg"" data-src="@BuildEffectImage(effectImage, 0, 625)" src="@ConfigHelper.CdnPrefix/Content/images/NewHome/white.png" class="coverimage" height="625" onload="AutoResizeImage(830, 0, this);" /></center>
error picture